Class: GSGraph::Auth
- Inherits:
-
Object
- Object
- GSGraph::Auth
- Defined in:
- lib/gs_graph/auth.rb,
lib/gs_graph/auth/cookie.rb,
lib/gs_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
- #exchange_token!(access_token) ⇒ Object
- #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 21 |
# File 'lib/gs_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(GSGraph::graph_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
#access_token ⇒ Object
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/gs_graph/auth.rb', line 5 def access_token @access_token end |
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/gs_graph/auth.rb', line 5 def client @client end |
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/gs_graph/auth.rb', line 5 def data @data end |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'lib/gs_graph/auth.rb', line 5 def user @user end |
Instance Method Details
#authorize_uri(canvas_uri, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gs_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 |
#authorized? ⇒ Boolean
23 24 25 |
# File 'lib/gs_graph/auth.rb', line 23 def self.access_token.present? end |
#exchange_token!(access_token) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/gs_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 |
#from_cookie(cookie) ⇒ Object
38 39 40 41 42 |
# File 'lib/gs_graph/auth.rb', line 38 def () self.data = Cookie.parse(client, ) get_access_token! data[:code] self end |
#from_signed_request(signed_request) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/gs_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 |