Skip to content

Instantly share code, notes, and snippets.

@Sephi-Chan
Created January 19, 2012 11:12
Show Gist options
  • Save Sephi-Chan/1639455 to your computer and use it in GitHub Desktop.
Save Sephi-Chan/1639455 to your computer and use it in GitHub Desktop.
require "rubygems"
require "sinatra"
require "oauth2"
get "/" do
haml :index
end
get "/facebook/sign_in" do
authorize_url = oauth_client.auth_code.authorize_url(redirect_uri: redirect_uri)
redirect to(authorize_url)
end
get "/facebook/callback" do
code = params[:code]
access_token = oauth_client.auth_code.get_token(code, redirect_uri: redirect_uri)
redirect to('/')
end
def oauth_client
api_key = "..."
secret_key = "..."
facebook_url = "https://graph.facebook.com"
OAuth2::Client.new(api_key, secret_key, site: facebook_url)
end
def redirect_uri
url('/facebook/callback')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment