Add these gems to your Gemfile and run
bundle install
gem "sinatra"
gem "oauth2"
client_id = "[YOUR_CLIENT_ID]"
client_secret = "[YOUR_CLIENT_SECRET]"
redirect_uri = "[YOUR_REDIRECT_URI]"
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 = "military"
Instantiate the OAuth 2.0 client
client = OAuth2::Client.new(client_id, client_secret, :authorize_url => authorization_url, :token_url => token_url, :scope => scope)
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
<span id="idme-wallet-button" data-scope="#{scope}" data-client-id="#{client_id}" data-redirect="#{redirect_uri}" data-response="code"></span> <script src="https://s3.amazonaws.com/idme/developer/idme-buttons/assets/js/idme-wallet-button.js"></script>
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)
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.