Web App

View the full sample project on Github

ADD DEPENDENCIES

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

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

CONFIGURE YOUR CLIENT SETTINGS AND SECRETS

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

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;

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' => 'military'
]);

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 and verification statuses from the payload['attributes'] and payload['status'] arrays.