Class: FbGraph::Auth
- Inherits:
-
Object
- Object
- FbGraph::Auth
- Defined in:
- lib/fb_graph/auth.rb,
lib/fb_graph/auth/cookie.rb,
lib/fb_graph/auth/signed_request.rb
Defined Under Namespace
Classes: Cookie, SignedRequest, VerificationFailed
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#client ⇒ Object
Returns the value of attribute client.
-
#data ⇒ Object
Returns the value of attribute data.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #authorize_uri(canvas_uri, options = {}) ⇒ Object
- #authorized? ⇒ Boolean
- #from_cookie(cookie) ⇒ Object
- #from_signed_request(signed_request) ⇒ 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.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fb_graph/auth.rb', line 7 def initialize(client_id, client_secret, = {}) @client = Rack::OAuth2::Client.new( :identifier => client_id, :secret => client_secret, :host => URI.parse(ROOT_URL).host, :authorization_endpoint => '/oauth/authorize', :token_endpoint => '/oauth/access_token' ) if [:cookie] [:cookie] elsif [:signed_request] from_signed_request [:signed_request] end end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/fb_graph/auth.rb', line 5 def access_token @access_token end |
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/fb_graph/auth.rb', line 5 def client @client end |
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/fb_graph/auth.rb', line 5 def data @data end |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'lib/fb_graph/auth.rb', line 5 def user @user end |
Instance Method Details
#authorize_uri(canvas_uri, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fb_graph/auth.rb', line 26 def (canvas_uri, = {}) endpoint = URI.parse SignedRequest::OAUTH_DIALOG_ENDPOINT params = .merge( :client_id => self.client.identifier, :redirect_uri => canvas_uri ) params[:scope] = Array(params[:scope]).join(',') if params[:scope].present? endpoint.query = params.to_query endpoint.to_s end |
#authorized? ⇒ Boolean
22 23 24 |
# File 'lib/fb_graph/auth.rb', line 22 def self.access_token.present? end |
#from_cookie(cookie) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/fb_graph/auth.rb', line 37 def () data = Cookie.parse(self.client, ) self.access_token = build_access_token(data) self.user = User.new(data[:uid], :access_token => self.access_token) self.data = data self end |
#from_signed_request(signed_request) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/fb_graph/auth.rb', line 45 def from_signed_request(signed_request) data = SignedRequest.verify(self.client, signed_request) if data[:oauth_token] self.access_token = build_access_token(data) self.user = User.new(data[:user_id], :access_token => self.access_token) end self.data = data self end |