-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
47 lines (38 loc) · 922 Bytes
/
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
require 'rubygems'
require 'haml'
require 'passport'
require 'sinatra'
enable :sessions
use Rack::Context
use Passport::Filter
Passport.configure("tokens.yml")
get "/" do
haml :index
end
post "/" do
Passport.authenticate do |token|
session[:facebook] = token.to_hash
redirect "/profile"
end
end
get "/profile" do
token = FacebookToken.new(session[:facebook])
@me = JSON.parse(token.get("/me"))
haml :show
end
__END__
@@ layout
!!! 5
%head
%title Passport Sinatra
%body
= yield
@@ index
%form{:action => "/", :method => :post}
%input{:type => :hidden, :name => :oauth_provider, :value => :facebook}
%input{:type => :hidden, :name => :authentication_type, :value => :user}
%input{:type => :submit, :value => "Login with Facebook"}
@@ show
%a{:href => @me["link"]}
%h1= "#{@me["name"]}, Your on Facebook!"
%img{:src => "https://graph.facebook.com/#{@me["id"]}/picture"}