PHPackages                             michaelkaefer/oauth2-amazon - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. michaelkaefer/oauth2-amazon

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

michaelkaefer/oauth2-amazon
===========================

Amazon OAuth 2.0 support for the PHP League's OAuth 2.0 Client

1.0.3(8y ago)697.6k↓14.4%5MITPHPCI failing

Since Apr 15Pushed 6y ago2 watchersCompare

[ Source](https://github.com/michaelKaefer/oauth2-amazon)[ Packagist](https://packagist.org/packages/michaelkaefer/oauth2-amazon)[ RSS](/packages/michaelkaefer-oauth2-amazon/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Amazon Provider for OAuth 2.0 Client
====================================

[](#amazon-provider-for-oauth-20-client)

This package provides Amazon OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

Installation
------------

[](#installation)

```
composer require michaelkaefer/oauth2-amazon

```

Usage
-----

[](#usage)

```
$amazonProvider = new \MichaelKaefer\OAuth2\Client\Provider\Amazon([
    'clientId'                => 'yourId',          // The client ID assigned to you by Amazon
    'clientSecret'            => 'yourSecret',      // The client password assigned to you by Amazon
    'redirectUri'             => 'yourRedirectUri'  // The return URL you specified for your app on Amazon
]);

// Get authorization code
if (!isset($_GET['code'])) {
    // Options are optional, defaults to 'profile' only
    $options = ['scope' => 'profile postal_code payments:widget payments:shipping_address payments:billing_address'];
    // Get authorization URL
    $authorizationUrl = $amazonProvider->getAuthorizationUrl($options);

    // Get state and store it to the session
    $_SESSION['oauth2state'] = $amazonProvider->getState();

    // Redirect user to authorization URL
    header('Location: ' . $authorizationUrl);
    exit;
// Check for errors
} elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) {
    if (isset($_SESSION['oauth2state'])) {
        unset($_SESSION['oauth2state']);
    }
    exit('Invalid state');
} else {
    // Get access token
    try {
        $accessToken = $amazonProvider->getAccessToken(
            'authorization_code',
            [
                'code' => $_GET['code']
            ]
        );
    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
        exit($e->getMessage());
    }

    // Get resource owner
    try {
        $resourceOwner = $amazonProvider->getResourceOwner($accessToken);
    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
        exit($e->getMessage());
    }

    // Now you can store the results to session etc.
    $_SESSION['accessToken'] = $accessToken;
    $_SESSION['resourceOwner'] = $resourceOwner;

    var_dump(
        $resourceOwner->getId(),
        $resourceOwner->getName(),
        $resourceOwner->getPostalCode(),
        $resourceOwner->getEmail(),
        $resourceOwner->toArray()
    );
}
```

For more information see the PHP League's general usage examples.

Testing
-------

[](#testing)

```
$ ./vendor/bin/phpunit
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/michaelKaefer/oauth2-amazon/blob/master/LICENSE) for more information.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

2955d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f49f39c9c35d3eb3d2a5f647da95c26e0f11e871f5e54b29c08e6608d8087a2a?d=identicon)[michaelKaefer](/maintainers/michaelKaefer)

---

Top Contributors

[![michaelKaefer](https://avatars.githubusercontent.com/u/13886409?v=4)](https://github.com/michaelKaefer "michaelKaefer (5 commits)")

---

Tags

phpapiclientamazonAuthenticationoauthoauth2authorization

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/michaelkaefer-oauth2-amazon/health.svg)

```
[![Health](https://phpackages.com/badges/michaelkaefer-oauth2-amazon/health.svg)](https://phpackages.com/packages/michaelkaefer-oauth2-amazon)
```

###  Alternatives

[league/oauth2-google

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

42121.2M118](/packages/league-oauth2-google)[andalisolutions/oauth2-anaf

Anaf OAuth 2.0 support for the PHP League's OAuth 2.0 Client

194.1k](/packages/andalisolutions-oauth2-anaf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
