Sha256: 35dd56210b7fc3a696469f0787e13db6c262c4a8bd6981996f6a357847d23f6f
Contents?: true
Size: 1.39 KB
Versions: 12
Compression:
Stored size: 1.39 KB
Contents
module FbGraph # = Parse & verify facebook auth cookie # # Used with Facebook JavaScript SDK # # app = FbGraph::Auth.new(APP_ID, APP_SECRET) # app.from_cookie(cookie_hash) # 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 class Auth class VerificationFailed < FbGraph::Exception; end attr_accessor :client, :access_token, :user def initialize(client_id, client_secret, options = {}) @client = OAuth2::Client.new(client_id, client_secret, options.merge( :site => FbGraph::ROOT_URL )) if options[:cookie].present? from_cookie(options[:cookie]) end end def from_cookie(cookie) cookie = FbGraph::Auth::Cookie.parse(self.client, cookie) expires_in = unless cookie[:expires].zero? cookie[:expires] - Time.now.to_i end self.access_token = OAuth2::AccessToken.new( self.client, cookie[:access_token], cookie[:refresh_token], expires_in ) self.user = FbGraph::User.new(cookie[:uid], :access_token => self.access_token) self end end end require 'fb_graph/auth/cookie'
Version data entries
12 entries across 12 versions & 1 rubygems