Created
June 11, 2018 11:10
-
-
Save amolpujari/c62050a426e1c5a09ea09ed36f62a9ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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