forked from rafmagana/Faceboku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaceboku.rb
47 lines (37 loc) · 1.28 KB
/
faceboku.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
require 'sinatra'
require 'omniauth/oauth'
# workaround for ruby 1.9.2 with sinatra 1.0. See: http://stackoverflow.com/questions/3973402/sinatra-app-doesnt-start-on-run
enable :run
enable :sessions
APP_ID = "153304591365687"
APP_SECRET = "7a7663099ccb62f180d985ba1252a3e2"
use OmniAuth::Builder do
provider :facebook, APP_ID, APP_SECRET, { :scope => 'email, status_update, publish_stream' }
end
get '/' do
@articles = []
@articles << {:title => 'Introduction to Heroku', :url => 'http://docs.heroku.com/heroku'}
@articles << {:title => 'Deploying Rack-based apps in Heroku', :url => 'http://docs.heroku.com/rack'}
@articles << {:title => 'Learn Ruby in twenty minutes', :url => 'http://www.ruby-lang.org/en/documentation/quickstart/'}
erb :index
end
get '/auth/facebook/callback' do
session['fb_auth'] = request.env['omniauth.auth']
session['fb_token'] = session['fb_auth']['credentials']['token']
session['fb_error'] = nil
redirect '/'
end
get '/auth/failure' do
clear_session
session['fb_error'] = 'In order to use this site you must allow us access to your Facebook data<br />'
redirect '/'
end
get '/logout' do
clear_session
redirect '/'
end
def clear_session
session['fb_auth'] = nil
session['fb_token'] = nil
session['fb_error'] = nil
end