PHPackages                             mrbulkinaleksey/oauth2-apple - 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. mrbulkinaleksey/oauth2-apple

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

mrbulkinaleksey/oauth2-apple
============================

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

0.2.10.10(2y ago)057MITPHP

Since Oct 18Pushed 2y agoCompare

[ Source](https://github.com/MrBulkinAleksey/oauth2-apple)[ Packagist](https://packagist.org/packages/mrbulkinaleksey/oauth2-apple)[ RSS](/packages/mrbulkinaleksey-oauth2-apple/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (15)Used By (0)

Sign in with Apple ID Provider for OAuth 2.0 Client
===================================================

[](#sign-in-with-apple-id-provider-for-oauth-20-client)

[![Latest Version](https://camo.githubusercontent.com/099c5360686d7d14ec16b11f5988bba410cbc57a15fdface7b64624b5f921d2a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7061747269636b627573736d616e6e2f6f61757468322d6170706c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/patrickbussmann/oauth2-apple/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/957094ca61bec01d638280650631b4820f95598cd54b732c2e51b9f03eb5d854/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7061747269636b627573736d616e6e2f6f61757468322d6170706c652f6d61696e2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/patrickbussmann/oauth2-apple)[![Coverage Status](https://camo.githubusercontent.com/cf6ce6a5ffafb1b9cc0ed0351ac0f6c7339435508efa38faebafd747cc979652/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7061747269636b627573736d616e6e2f6f61757468322d6170706c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/patrickbussmann/oauth2-apple/code-structure)[![Quality Score](https://camo.githubusercontent.com/d3678ffe87ce3ebb2112722ce7fff162f87a1d8772fb09f87628003f253b6885/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7061747269636b627573736d616e6e2f6f61757468322d6170706c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/patrickbussmann/oauth2-apple)[![codecov](https://camo.githubusercontent.com/77a6f8718b044cd18c92d919a5186118e68b06fd7e451c1d99d403388efd7879/68747470733a2f2f636f6465636f762e696f2f67682f7061747269636b627573736d616e6e2f6f61757468322d6170706c652f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d544e335a4e5648555856)](https://codecov.io/gh/patrickbussmann/oauth2-apple)[![Total Downloads](https://camo.githubusercontent.com/9ac117dc75a80059a6273504e19ab3d26effc9a2e579c51e34f145e494d67c52/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7061747269636b627573736d616e6e2f6f61757468322d6170706c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/patrickbussmann/oauth2-apple)

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

Before You Begin
----------------

[](#before-you-begin)

Here you can find the official Apple documentation:

If you request email address or name please note that you'll get this only in your first login. When you log in a second time you will only get the user id - nothing more. Maybe Apple changes this sometime.

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

[](#installation)

To install, use composer:

```
composer require patrickbussmann/oauth2-apple

```

Usage
-----

[](#usage)

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

### Authorization Code Flow

[](#authorization-code-flow)

```
// $leeway is needed for clock skew
Firebase\JWT\JWT::$leeway = 60;

$provider = new League\OAuth2\Client\Provider\Apple([
    'clientId'          => '{apple-client-id}',
    'teamId'            => '{apple-team-id}', // 1A234BFK46 https://developer.apple.com/account/#/membership/ (Team ID)
    'keyFileId'         => '{apple-key-file-id}', // 1ABC6523AA https://developer.apple.com/account/resources/authkeys/list (Key ID)
    'keyFilePath'       => '{apple-key-file-path}', // __DIR__ . '/AuthKey_1ABC6523AA.p8' -> Download key above
    'redirectUri'       => 'https://example.com/callback-url',
]);

if (!isset($_POST['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: '.$authUrl);
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_POST['state']) || ($_POST['state'] !== $_SESSION['oauth2state'])) {

    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

    // Try to get an access token (using the authorization code grant)
    /** @var AppleAccessToken $token */
    $token = $provider->getAccessToken('authorization_code', [
        'code' => $_POST['code']
    ]);

    // Optional: Now you have a token you can look up a users profile data
    // Important: The most details are only visible in the very first login!
    // In the second and third and ... ones you'll only get the identifier of the user!
    try {

        // We got an access token, let's now get the user's details
        $user = $provider->getResourceOwner($token);

        // Use these details to create a new profile
        printf('Hello %s!', $user->getFirstName());

    } catch (Exception $e) {

        // Failed to get user details
        exit(':-(');
    }

    // Use this to interact with an API on the users behalf
    echo $token->getToken();
}
```

### Revoke Code Flow

[](#revoke-code-flow)

```
// $leeway is needed for clock skew
Firebase\JWT\JWT::$leeway = 60;

$provider = new League\OAuth2\Client\Provider\Apple([
    'clientId'          => '{apple-client-id}',
    'teamId'            => '{apple-team-id}', // 1A234BFK46 https://developer.apple.com/account/#/membership/ (Team ID)
    'keyFileId'         => '{apple-key-file-id}', // 1ABC6523AA https://developer.apple.com/account/resources/authkeys/list (Key ID)
    'keyFilePath'       => '{apple-key-file-path}', // __DIR__ . '/AuthKey_1ABC6523AA.p8' -> Download key above
    'redirectUri'       => 'https://example.com/callback-url',
]);

$token = $token->getToken(); // Use the token of "Authorization Code Flow" which you saved somewhere for the user

try {
    $provider->revokeAccessToken($token /*, 'access_token' or 'refresh_token' */);
    // Successfully revoked the token!

} catch (Exception $e) {

    // Failed to revoke
    exit(':-(');
}
```

### Managing Scopes

[](#managing-scopes)

When creating your Apple authorization URL, you can specify the state and scopes your application may authorize.

```
$options = [
    'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
    // Scopes: https://developer.apple.com/documentation/authenticationservices/asauthorizationscope
    'scope' => ['name', 'email'] // array or string
];

$authorizationUrl = $provider->getAuthorizationUrl($options);
```

If neither are defined, the provider will utilize internal defaults.

At the time of authoring this documentation, the following scopes are available.

- name (default)
- email (default)

Please note that you will get this informations only at the first log in of the user! In the following log ins you'll get only the user id!

If you only want to get the user id, you can set the `scope` as ` `, then change all the `$_POST` to `$_GET`.

### Refresh Tokens

[](#refresh-tokens)

If your access token expires you can refresh them with the refresh token.

```
$refreshToken = $token->getRefreshToken();
$refreshTokenExpiration = $token->getRefreshTokenExpires();

```

Testing
-------

[](#testing)

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

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/patrickbussmann/oauth2-apple/blob/main/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [All Contributors](https://github.com/patrickbussmann/oauth2-apple/contributors)

Template for this repository was the [LinkedIn](https://github.com/thephpleague/oauth2-linkedin).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/patrickbussmann/oauth2-apple/blob/main/LICENSE) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.1% 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 ~136 days

Recently: every ~179 days

Total

13

Last Release

755d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e1703d3816f73abe608ddbb31f0e817db70875a9fa81ed0926a2caf36990386?d=identicon)[MrBulkinAleksey](/maintainers/MrBulkinAleksey)

---

Top Contributors

[![patrickbussmann](https://avatars.githubusercontent.com/u/15617021?v=4)](https://github.com/patrickbussmann "patrickbussmann (25 commits)")[![stefanorosanelli](https://avatars.githubusercontent.com/u/2122280?v=4)](https://github.com/stefanorosanelli "stefanorosanelli (3 commits)")[![pradtke](https://avatars.githubusercontent.com/u/932934?v=4)](https://github.com/pradtke "pradtke (2 commits)")[![MrBulkinAleksey](https://avatars.githubusercontent.com/u/13556540?v=4)](https://github.com/MrBulkinAleksey "MrBulkinAleksey (2 commits)")[![tjveldhuizen](https://avatars.githubusercontent.com/u/779998?v=4)](https://github.com/tjveldhuizen "tjveldhuizen (2 commits)")[![williamxsp](https://avatars.githubusercontent.com/u/3438192?v=4)](https://github.com/williamxsp "williamxsp (2 commits)")[![adrianbardan](https://avatars.githubusercontent.com/u/2693350?v=4)](https://github.com/adrianbardan "adrianbardan (1 commits)")[![zhangv](https://avatars.githubusercontent.com/u/496221?v=4)](https://github.com/zhangv "zhangv (1 commits)")[![bashgeek](https://avatars.githubusercontent.com/u/4669888?v=4)](https://github.com/bashgeek "bashgeek (1 commits)")[![deguif](https://avatars.githubusercontent.com/u/993399?v=4)](https://github.com/deguif "deguif (1 commits)")[![NaxYo](https://avatars.githubusercontent.com/u/1963876?v=4)](https://github.com/NaxYo "NaxYo (1 commits)")[![NgSekLong](https://avatars.githubusercontent.com/u/12507208?v=4)](https://github.com/NgSekLong "NgSekLong (1 commits)")[![theedov](https://avatars.githubusercontent.com/u/30866972?v=4)](https://github.com/theedov "theedov (1 commits)")

---

Tags

clientoauthoauth2authorizationauthorisationapplesign in with apple

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mrbulkinaleksey-oauth2-apple/health.svg)

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

###  Alternatives

[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[stevenmaguire/oauth2-keycloak

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

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2509.6M48](/packages/thenetworg-oauth2-azure)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

251.7M1](/packages/mollie-oauth2-mollie-php)

PHPackages © 2026

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