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 = ""
token_url         = ""
attributes_url    = ""
scope             = "YOUR_SCOPE_VALUE"

Instantiate the OAuth 2.0 client

client =, client_secret, :authorize_url => authorization_url, :token_url => token_url, :scope => scope)}

Step 3. Redirect the user to'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 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's API

Use the access token to call'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.