lemonstand/oauth2-amazon

Amazon OAuth 2.0 Client Provider for The PHP League OAuth2-Client

dev-master 2015-05-29 07:00 UTC

This package is not auto-updated.

Last update: 2024-11-09 18:20:08 UTC


README

Build Status Coverage Status License Total Downloads

This package provides Amazon OAuth 2.0 support for the PHP League's OAuth 2.0 Client.

Installation

To install, use composer:

composer require lemonstand/oauth2-amazon

Usage

Usage is the same as The League's OAuth client, using LemonStand\OAuth2\Client\Provider\Amazon as the provider.

Authorization Code Flow

$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);
}

Refreshing A 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]);