-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
55 lines (45 loc) · 1.54 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Facebook < Padrino::Application
register Padrino::Helpers
register Padrino::Admin::AccessControl
configure do
enable :sessions
disable :store_location
set :views, File.dirname(__FILE__) + '/views'
yml = YAML::load(File.open(File.dirname(__FILE__) + "/facebook_app_config.yml"))
set :app_id, yml["app_id"]
set :app_name, yml["app_name"]
set :app_secret, yml["app_secret"]
set :app_url, yml["app_url"]
end
get '/login' do
oauth_client = OAuth2::Client.new(settings.app_id, settings.app_url, {
:authorize_url => 'https://www.facebook.com/dialog/oauth'
})
redirect oauth_client.authorize_url({
:client_id => settings.app_id,
:redirect_uri => settings.app_url,
:scope => 'email'
})
end
get '/' do
oauth_client = OAuth2::Client.new(settings.app_id, settings.app_secret, {
:site => 'https://graph.facebook.com',
:token_url => '/oauth/access_token'
})
begin
access_token = oauth_client.get_token({
:client_id => settings.app_id,
:client_secret => settings.app_secret,
:redirect_uri => settings.app_url,
:code => params[:code],
:parse => :query
})
rescue Error => e
puts "Error happened: #{e}"
end
access_token.options[:mode] = :query
access_token.options[:param_name] = :access_token
@facebook_user = access_token.get('/me', {:parse => :json}).parsed
erb :details
end
end