This package provides Amazon OAuth 2.0 support for the PHP League's OAuth 2.0 Client.
To install, use composer:
composer require lemonstand/oauth2-amazon
Usage is the same as The League's OAuth client, using LemonStand\OAuth2\Client\Provider\Amazon
as the provider.
$provider = new LemonStand\OAuth2\Client\Provider\Amazon([
'clientId' => 'YOUR_CLIENT_ID',
'clientSecret' => 'YOUR_CLIENT_SECRET',
'redirectUri' => 'http://your-redirect-uri',
]);
$provider->testMode = true; // Allows you to work in Amazon's Sandbox environment.
if (isset($_GET['code']) && $_GET['code']) {
$token = $this->provider->getAccessToken('authorizaton_code', [
'code' => $_GET['code']
]);
// Returns an instance of League\OAuth2\Client\User
$user = $this->provider->getUserDetails($token);
$uid = $provider->getUserUid($token);
$email = $provider->getUserEmail($token);
$screenName = $provider->getUserScreenName($token);
}
$provider = new LemonStand\OAuth2\Client\Provider\Amazon([
'clientId' => 'YOUR_CLIENT_ID',
'clientSecret' => 'YOUR_CLIENT_SECRET',
'redirectUri' => 'http://your-redirect-uri',
]);
$grant = new \League\OAuth2\Client\Grant\RefreshToken();
$token = $provider->getAccessToken($grant, ['refresh_token' => $refreshToken]);