Created
January 20, 2012 09:16
-
-
Save jugyo/1646320 to your computer and use it in GitHub Desktop.
an example of auth for facebook
This file contains hidden or 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 'thread' | |
require 'facebook_oauth' | |
require 'launchy' | |
require 'sinatra/base' | |
callback_uri = URI.parse('http://localhost:6789/') | |
fb_client = FacebookOAuth::Client.new( | |
:application_id => 'XXXXXXXXXXXX', | |
:application_secret => 'XXXXXXXXXXXXXXXXXXXXXXXX', | |
:callback => callback_uri.to_s | |
) | |
class CallbackHanlder < Sinatra::Base | |
get '/' do | |
res = if params[:code] | |
settings.fb_client.authorize(:code => params[:code]) | |
else | |
'error' | |
end | |
Thread.start do | |
sleep 1 | |
$_callback_hanlder_server.stop | |
end | |
res | |
end | |
end | |
authorize_url = fb_client.authorize_url | |
puts "open #{authorize_url}" | |
Launchy.open(authorize_url) | |
CallbackHanlder.run!(:port => callback_uri.port, :fb_client => fb_client) do |server| | |
$_callback_hanlder_server = server | |
end | |
p fb_client.me.info | |
puts "access_token: #{fb_client.send(:access_token).token}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment