PHPackages                             marsaldev/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. marsaldev/oauth2-amazon

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

marsaldev/oauth2-amazon
=======================

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

v1.0.2(1mo ago)04MITPHPPHP ^8.2

Since Jul 8Pushed 1mo agoCompare

[ Source](https://github.com/marsaldev/oauth2-amazon)[ Packagist](https://packagist.org/packages/marsaldev/oauth2-amazon)[ Docs](https://github.com/marsaldev/oauth2-amazon)[ RSS](/packages/marsaldev-oauth2-amazon/feed)WikiDiscussions master Synced 1w 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 marsaldev/oauth2-amazon

```

Amazon Setup
------------

[](#amazon-setup)

Before you can use this provider, you need to register your application with Amazon to get a Client ID and Client Secret:

1. Sign in to the [Amazon Developer Console](https://developer.amazon.com/).
2. Go to **Apps &amp; Services → Login with Amazon** and click **Create a New Security Profile**.
3. Fill in the **Security Profile Name**, **Security Profile Description**, and **Consent Privacy Notice URL**, then save.
4. Open the security profile you just created and go to the **Web Settings** tab: this is where you'll find your **Client ID** and **Client Secret**.
5. Still under **Web Settings**, click **Edit** and set:
    - **Allowed Origins** — the origin(s) your application is served from (e.g. `https://example.com`)
    - **Allowed Return URLs** — the exact redirect URI your app uses to receive the authorization code; this must match the `redirectUri` passed to the provider below
6. Use the Client ID, Client Secret, and redirect URI in your application as shown in [Usage](#usage) below.

Note: the `profile` scope is granted by default. The `postal_code` scope and the `payments:*`scopes used in the example below are tied to Amazon Pay and may require your security profile to be separately approved for those APIs before Amazon will grant them.

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/marsaldev/oauth2-amazon/blob/master/LICENSE) for more information.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% 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

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/10f5c30b5925967887e9f193f140343995ed578d87b93a093d98a498dd748ed6?d=identicon)[marsaldev](/maintainers/marsaldev)

---

Top Contributors

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

---

Tags

phpapiclientamazonAuthenticationoauthoauth2authorization

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/oauth2-google

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

42524.2M200](/packages/league-oauth2-google)[andalisolutions/oauth2-anaf

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

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

PHPackages © 2026

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