Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Rack::OAuth2::Client Sample - Token Request
require 'rubygems'
require 'rack/oauth2'
client =
:identifier => YOUR_CLIENT_ID,
:redirect_uri => YOUR_REDIRECT_URI, # only required for grant_type = :code
:host => ''
grant_type = :authorization_code
puts "## grant_type = :#{grant_type}"
case grant_type
when :client_credentials
# Nothing to do
when :password
client.resource_owner_credentials = YOUR_USERNAME, YOUR_PASSWORD
when :authorization_code
client.authorization_code = YOUR_AUTHORIZATION_CODE
when :refresh_token
client.refresh_token = YOUR_REFRESH_TOKEN_FOR_USER
p client.access_token!
rescue => e
p e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.