Class: FbGraph::Auth
- Inherits:
-
Object
- Object
- FbGraph::Auth
- Defined in:
- lib/fb_graph/auth.rb,
lib/fb_graph/auth/cookie.rb
Overview
Parse & verify facebook auth cookie
Used with Facebook JavaScript SDK
app = FbGraph::Auth.new(APP_ID, APP_SECRET)
app.()
auth.access_token
# => OAuth2::AccessToken (not String!)
auth.user # only initialized
auth.user.fetch # fetch whole profile
This method is called automatically if cookie is given when initializing
auth = FbGraph::Auth.new(APP_ID, APP_SECRET, :cookie => {..})
auth.access_token # already parsed
Defined Under Namespace
Classes: Cookie, VerificationFailed
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#client ⇒ Object
Returns the value of attribute client.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #from_cookie(cookie) ⇒ Object
-
#initialize(client_id, client_secret, options = {}) ⇒ Auth
constructor
A new instance of Auth.
Constructor Details
#initialize(client_id, client_secret, options = {}) ⇒ Auth
Returns a new instance of Auth.
22 23 24 25 26 27 28 29 |
# File 'lib/fb_graph/auth.rb', line 22 def initialize(client_id, client_secret, = {}) @client = OAuth2::Client.new(client_id, client_secret, .merge( :site => FbGraph::ROOT_URL )) if [:cookie].present? ([:cookie]) end end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
20 21 22 |
# File 'lib/fb_graph/auth.rb', line 20 def access_token @access_token end |
#client ⇒ Object
Returns the value of attribute client.
20 21 22 |
# File 'lib/fb_graph/auth.rb', line 20 def client @client end |
#user ⇒ Object
Returns the value of attribute user.
20 21 22 |
# File 'lib/fb_graph/auth.rb', line 20 def user @user end |
Instance Method Details
#from_cookie(cookie) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fb_graph/auth.rb', line 31 def () #this creates a cookie = FbGraph::Auth::Cookie.parse(self.client, ) #the cookie expires time is the time as an integer #in the oauth2 api, it does Time.now + expires, creating a time too large #instead, make expires a delta value time_expires = [:expires].to_i - Time.now.to_i self.access_token = OAuth2::AccessToken.new( self.client, [:access_token], [:refresh_token], time_expires ) self.user = FbGraph::User.new([:uid], :access_token => self.access_token) self end |