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)
-
- (Object) access_token
Returns the value of attribute access_token.
-
- (Object) client
Returns the value of attribute client.
-
- (Object) data
Returns the value of attribute data.
-
- (Object) user
Returns the value of attribute user.
Instance Method Summary (collapse)
- - (Object) authorize_uri(canvas_uri, options = {})
- - (Boolean) authorized?
- - (Object) exchange_token!(access_token)
- - (Object) from_cookie(cookie)
- - (Object) from_signed_request(signed_request)
-
- (Auth) initialize(client_id, client_secret, options = {})
constructor
A new instance of Auth.
Constructor Details
- (Auth) initialize(client_id, client_secret, options = {})
A new instance of Auth
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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', :redirect_uri => [:redirect_uri] ) if [:cookie] [:cookie] elsif [:signed_request] from_signed_request [:signed_request] end end |
Instance Attribute Details
- (Object) access_token
Returns the value of attribute access_token
5 6 7 |
# File 'lib/fb_graph/auth.rb', line 5 def access_token @access_token end |
- (Object) client
Returns the value of attribute client
5 6 7 |
# File 'lib/fb_graph/auth.rb', line 5 def client @client end |
- (Object) data
Returns the value of attribute data
5 6 7 |
# File 'lib/fb_graph/auth.rb', line 5 def data @data end |
- (Object) user
Returns the value of attribute user
5 6 7 |
# File 'lib/fb_graph/auth.rb', line 5 def user @user end |
Instance Method Details
- (Object) authorize_uri(canvas_uri, options = {})
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fb_graph/auth.rb', line 27 def (canvas_uri, = {}) endpoint = URI.parse SignedRequest::OAUTH_DIALOG_ENDPOINT params = .merge( :client_id => 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 |
- (Boolean) authorized?
23 24 25 |
# File 'lib/fb_graph/auth.rb', line 23 def self.access_token.present? end |
- (Object) exchange_token!(access_token)
53 54 55 56 57 58 59 60 |
# File 'lib/fb_graph/auth.rb', line 53 def exchange_token!(access_token) raise Unauthorized.new('No Access Token') unless access_token client.fb_exchange_token = access_token self.access_token = client.access_token! :client_auth_body self rescue Rack::OAuth2::Client::Error => e Exception.handle_rack_oauth2_error e end |
- (Object) from_cookie(cookie)
38 39 40 41 42 |
# File 'lib/fb_graph/auth.rb', line 38 def () self.data = Cookie.parse(client, ) get_access_token! data[:code] self end |
- (Object) from_signed_request(signed_request)
44 45 46 47 48 49 50 51 |
# File 'lib/fb_graph/auth.rb', line 44 def from_signed_request(signed_request) self.data = SignedRequest.verify(client, signed_request) if self.data[:oauth_token] self.access_token = build_access_token(data) self.user = User.new(data[:user_id], :access_token => self.access_token) end self end |