Ruby Web App
Choose API Version:
V3 V2

View the full sample project on Github

Step 1. Add dependencies

Add these gems to your Gemfile and run bundle install

gem "sinatra"
gem "oauth2"

Step 2. Configure your client settings and secrets

client_id         = "[YOUR_CLIENT_ID]"
client_secret     = "[YOUR_CLIENT_SECRET]"
redirect_uri      = "http://localhost:4567/callback"
authorization_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             = "YOUR_SCOPE_VALUE"

Instantiate the OAuth 2.0 client

client = OAuth2::Client.new(client_id, client_secret, :authorize_url => authorization_url, :token_url => token_url, :scope => scope)}

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

Generate the authorization endpoint URL

auth_endpoint = client.auth_code.authorize_url(:redirect_uri => redirect_uri)

Create a link to send the user to the auth endpoint auth_endpoint

<a href="#{auth_endpoint}">Link to ID.me Auth Server</a>

Step 4. Exchange the code for an access token

Use the auth_code and get_token methods to exchange the authorization code for an access token

token = client.auth_code.get_token(params[:code], :redirect_uri => redirect_uri)

Step 5. Call ID.me's API

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

payload = token.get(attributes_url).parsed

You can check the user's attributes and verification statuses from the payload['attributes'] and payload['status']arrays.