Python Web App
Choose API Version:
V3 V2

View the full sample project on Github

Step 1. Add dependencies

Add the requests-oauthlib dependency to your requirements.txt and run pip install -r requirements.txt

flask
requests-oauthlib

Step 2. Configure your client settings and secrets

client_id              = '[YOUR_CLIENT_ID]'
client_secret          = '[YOUR_CLIENT_SECRET]'
redirect_uri           = '[YOUR_REDIRECT_URI]'
authorization_base_url = 'https://api.id.me/oauth/authorize'
token_url              = 'https://api.id.me/oauth/token'
attributes_url         = 'https://api.id.me/api/public/v3/attributes.json'
scope                  = military

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

Generate the authorization endpoint URL

idme = OAuth2Session(client_id, redirect_uri=redirect_uri, scope=scope)
authorization_url = idme.authorization_url(authorization_base_url)

Redirect the user to the authorization_url

redirect(authorization_url)

Step 4. Exchange the code for an access token

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

token = idme.fetch_token(token_url, client_secret=client_secret, authorization_response=request.url)}

Step 5. Call ID.me's API

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

idme = OAuth2Session(client_id, token=token)
payload = idme.get('attributes_url').json()

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