{"id":20191332,"url":"https://github.com/patrickbussmann/oauth2-apple","last_synced_at":"2025-03-31T04:03:55.477Z","repository":{"id":35207837,"uuid":"216003810","full_name":"patrickbussmann/oauth2-apple","owner":"patrickbussmann","description":"Sign in with Apple Provider for the OAuth 2.0 Client","archived":false,"fork":false,"pushed_at":"2024-09-17T17:07:23.000Z","size":67,"stargazers_count":102,"open_issues_count":11,"forks_count":66,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-24T00:47:19.311Z","etag":null,"topics":["apple","sign-in-with-apple"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrickbussmann.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-18T10:55:08.000Z","updated_at":"2025-02-27T10:03:13.000Z","dependencies_parsed_at":"2024-05-17T19:47:57.083Z","dependency_job_id":"a6026709-a3c9-488b-9c60-4714ce133196","html_url":"https://github.com/patrickbussmann/oauth2-apple","commit_stats":{"total_commits":36,"total_committers":15,"mean_commits":2.4,"dds":0.4722222222222222,"last_synced_commit":"badae8f295ac953230551bd014a3981921df078e"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickbussmann%2Foauth2-apple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickbussmann%2Foauth2-apple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickbussmann%2Foauth2-apple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickbussmann%2Foauth2-apple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickbussmann","download_url":"https://codeload.github.com/patrickbussmann/oauth2-apple/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246413232,"owners_count":20773053,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apple","sign-in-with-apple"],"created_at":"2024-11-14T03:48:31.853Z","updated_at":"2025-03-31T04:03:55.454Z","avatar_url":"https://github.com/patrickbussmann.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sign in with Apple ID Provider for OAuth 2.0 Client\n[![Latest Version](https://img.shields.io/github/release/patrickbussmann/oauth2-apple.svg?style=flat-square)](https://github.com/patrickbussmann/oauth2-apple/releases)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/travis/patrickbussmann/oauth2-apple/main.svg?style=flat-square)](https://travis-ci.org/patrickbussmann/oauth2-apple)\n[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/patrickbussmann/oauth2-apple.svg?style=flat-square)](https://scrutinizer-ci.com/g/patrickbussmann/oauth2-apple/code-structure)\n[![Quality Score](https://img.shields.io/scrutinizer/g/patrickbussmann/oauth2-apple.svg?style=flat-square)](https://scrutinizer-ci.com/g/patrickbussmann/oauth2-apple)\n[![codecov](https://codecov.io/gh/patrickbussmann/oauth2-apple/branch/main/graph/badge.svg?token=TN3ZNVHUXV)](https://codecov.io/gh/patrickbussmann/oauth2-apple)\n[![Total Downloads](https://img.shields.io/packagist/dt/patrickbussmann/oauth2-apple.svg?style=flat-square)](https://packagist.org/packages/patrickbussmann/oauth2-apple)\n\nThis package provides Apple ID OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).\n\n## Before You Begin\n\nHere you can find the official Apple documentation:\nhttps://developer.apple.com/documentation/signinwithapplerestapi\n\nIf you request email address or name please note that you'll get this only in your first login.\nWhen you log in a second time you will only get the user id - nothing more.\nMaybe Apple changes this sometime.\n\n## Installation\n\nTo install, use composer:\n\n```\ncomposer require patrickbussmann/oauth2-apple\n```\n\n## Usage\n\nUsage is the same as The League's OAuth client, using `\\League\\OAuth2\\Client\\Provider\\Apple` as the provider.\n\n### Authorization Code Flow\n\n```php\n// $leeway is needed for clock skew\nFirebase\\JWT\\JWT::$leeway = 60;\n\n$provider = new League\\OAuth2\\Client\\Provider\\Apple([\n    'clientId'          =\u003e '{apple-client-id}',\n    'teamId'            =\u003e '{apple-team-id}', // 1A234BFK46 https://developer.apple.com/account/#/membership/ (Team ID)\n    'keyFileId'         =\u003e '{apple-key-file-id}', // 1ABC6523AA https://developer.apple.com/account/resources/authkeys/list (Key ID)\n    'keyFilePath'       =\u003e '{apple-key-file-path}', // __DIR__ . '/AuthKey_1ABC6523AA.p8' -\u003e Download key above\n    'redirectUri'       =\u003e 'https://example.com/callback-url',\n]);\n\nif (!isset($_POST['code'])) {\n\n    // If we don't have an authorization code then get one\n    $authUrl = $provider-\u003egetAuthorizationUrl();\n    $_SESSION['oauth2state'] = $provider-\u003egetState();\n    header('Location: '.$authUrl);\n    exit;\n\n// Check given state against previously stored one to mitigate CSRF attack\n} elseif (empty($_POST['state']) || ($_POST['state'] !== $_SESSION['oauth2state'])) {\n\n    unset($_SESSION['oauth2state']);\n    exit('Invalid state');\n\n} else {\n\n    // Try to get an access token (using the authorization code grant)\n    /** @var AppleAccessToken $token */\n    $token = $provider-\u003egetAccessToken('authorization_code', [\n        'code' =\u003e $_POST['code']\n    ]);\n\n    // Optional: Now you have a token you can look up a users profile data\n    // Important: The most details are only visible in the very first login!\n    // In the second and third and ... ones you'll only get the identifier of the user!\n    try {\n\n        // We got an access token, let's now get the user's details\n        $user = $provider-\u003egetResourceOwner($token);\n\n        // Use these details to create a new profile\n        printf('Hello %s!', $user-\u003egetFirstName());\n\n    } catch (Exception $e) {\n\n        // Failed to get user details\n        exit(':-(');\n    }\n\n    // Use this to interact with an API on the users behalf\n    echo $token-\u003egetToken();\n}\n```\n\n### Revoke Code Flow\n\n```php\n// $leeway is needed for clock skew\nFirebase\\JWT\\JWT::$leeway = 60;\n\n$provider = new League\\OAuth2\\Client\\Provider\\Apple([\n    'clientId'          =\u003e '{apple-client-id}',\n    'teamId'            =\u003e '{apple-team-id}', // 1A234BFK46 https://developer.apple.com/account/#/membership/ (Team ID)\n    'keyFileId'         =\u003e '{apple-key-file-id}', // 1ABC6523AA https://developer.apple.com/account/resources/authkeys/list (Key ID)\n    'keyFilePath'       =\u003e '{apple-key-file-path}', // __DIR__ . '/AuthKey_1ABC6523AA.p8' -\u003e Download key above\n    'redirectUri'       =\u003e 'https://example.com/callback-url',\n]);\n\n$token = $token-\u003egetToken(); // Use the token of \"Authorization Code Flow\" which you saved somewhere for the user\n\n\ntry {\n    $provider-\u003erevokeAccessToken($token /*, 'access_token' or 'refresh_token' */);\n    // Successfully revoked the token!\n\n} catch (Exception $e) {\n\n    // Failed to revoke\n    exit(':-(');\n}\n```\n\n### Managing Scopes\n\nWhen creating your Apple authorization URL, you can specify the state and scopes your application may authorize.\n\n```php\n$options = [\n    'state' =\u003e 'OPTIONAL_CUSTOM_CONFIGURED_STATE',\n    // Scopes: https://developer.apple.com/documentation/authenticationservices/asauthorizationscope\n    'scope' =\u003e ['name', 'email'] // array or string\n];\n\n$authorizationUrl = $provider-\u003egetAuthorizationUrl($options);\n```\nIf neither are defined, the provider will utilize internal defaults.\n\nAt the time of authoring this documentation, the following scopes are available.\n\n- name (default)\n- email (default)\n\nPlease note that you will get this informations only at the first log in of the user!\nIn the following log ins you'll get only the user id!\n\nIf you only want to get the user id, you can set the `scope` as ` `, then change all the `$_POST` to `$_GET`.\n\n### Refresh Tokens\n\nIf your access token expires you can refresh them with the refresh token.\n\n```\n$refreshToken = $token-\u003egetRefreshToken();\n$refreshTokenExpiration = $token-\u003egetRefreshTokenExpires();\n```\n\n## Testing\n\n``` bash\n$ ./vendor/bin/phpunit\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/patrickbussmann/oauth2-apple/blob/main/CONTRIBUTING.md) for details.\n\n\n## Credits\n\n- [All Contributors](https://github.com/patrickbussmann/oauth2-apple/contributors)\n\nTemplate for this repository was the [LinkedIn](https://github.com/thephpleague/oauth2-linkedin).\n\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/patrickbussmann/oauth2-apple/blob/main/LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickbussmann%2Foauth2-apple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickbussmann%2Foauth2-apple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickbussmann%2Foauth2-apple/lists"}