PHP Web App
Choose API Version:
V3 V2

View the full sample project on Github

Step 1. Add dependencies

Add the oauth2-client dependency to your composer.json and install with php composer.phar install

{
    "require": {
      "league/oauth2-client": "^1.1"
    }
}

Step 2. Configure your client settings and secrets

$provider = new \League\OAuth2\Client\Provider\GenericProvider([
    'clientId'                => '[YOUR_CLIENT_ID]',
    'clientSecret'            => '[YOUR_CLIENT_SECRET]',
    'redirectUri'             => '[YOUR_REDIRECT_URI]',
    'urlAuthorize'            => 'https://api.id.me/oauth/authorize',
    'urlAccessToken'          => 'https://api.id.me/oauth/token',
    'urlResourceOwnerDetails' => 'https://api.id.me/api/public/v3/attributes.json'
]);

Step 3. Redirect the user to ID.me's OAuth 2.0 server

Generate the authorization endpoint URL

$authorizationUrl = $provider->getAuthorizationUrl();

Redirect the user to $authorizationUrl

header('Location: ' . filter_var($authorizationUrl, FILTER_SANITIZE_URL));
exit;

Step 4. Exchange the code for an access token

Use the getAccessToken method to exchange the authorization code for an access token

$accessToken = $provider->getAccessToken('authorization_code', [
    'code' => $_GET['code'], 'scope' => 'kyc'
]);

Step 5. Call ID.me's API

Use the access token to call ID.me's API and retrieve the user's attributes

$payload = $provider->getResourceOwner($accessToken)->toArray();

You can check the user's attributes via $payload['attributes'] and $payload['status'] arrays.