Skip to content

Instantly share code, notes, and snippets.

@amolpujari
Created June 11, 2018 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amolpujari/c62050a426e1c5a09ea09ed36f62a9ef to your computer and use it in GitHub Desktop.
Save amolpujari/c62050a426e1c5a09ea09ed36f62a9ef to your computer and use it in GitHub Desktop.
require "sinatra"
require "oauth2"
DB = {
site: "http://api.local.com:3000/",
redirect_uri: "http://oauth2client:1758/callback"
}
get "/" do
DB[:uid] = params[:uid]
DB[:secret] = params[:secret]
client = OAuth2::Client.new( DB[:uid], DB[:secret], site: DB[:site])
url = client.auth_code.authorize_url( redirect_uri: DB[:redirect_uri])
redirect url
end
get "/callback" do
client = OAuth2::Client.new( DB[:uid], DB[:secret], site: DB[:site])
token = client.auth_code.get_token(params[:code], :redirect_uri => DB[:redirect_uri])
%{
connected:
<br/><br/>
#{token.to_hash}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment