Class: OmniAuth::Strategies::HackID
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::HackID
- Defined in:
- lib/omniauth/strategies/hackid.rb
Defined Under Namespace
Classes: NoAuthorizationCodeError
Constant Summary collapse
- DEFAULT_SCOPE =
'email'
Instance Method Summary collapse
- #access_token_options ⇒ Object
-
#authorize_params ⇒ Object
You can pass
display
,state
orscope
params to the auth request, if you need to set them dynamically. - #build_access_token ⇒ Object
-
#callback_url ⇒ Object
NOTE if we’re using code from the signed request then HackID sets the redirect_uri to ” during the authorize phase + it must match during the access_token phase: github.com/facebook/php-sdk/blob/master/src/base_facebook.php#L348.
- #raw_info ⇒ Object
- #request_phase ⇒ Object
-
#signed_request ⇒ Object
Parse signed request in order, from:.
Instance Method Details
#access_token_options ⇒ Object
110 111 112 |
# File 'lib/omniauth/strategies/hackid.rb', line 110 def ..inject({}) { |h,(k,v)| h[k.to_sym] = v; h } end |
#authorize_params ⇒ Object
You can pass display
, state
or scope
params to the auth request, if you need to set them dynamically. You can also set these options in the OmniAuth config :authorize_params option.
/auth/hackid?display=popup&state=ABC
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/omniauth/strategies/hackid.rb', line 121 def super.tap do |params| %w[display state scope].each do |v| if request.params[v] params[v.to_sym] = request.params[v] # to support omniauth-oauth2's auto csrf protection session['omniauth.state'] = params[:state] if v == 'state' end end params[:scope] ||= DEFAULT_SCOPE end end |
#build_access_token ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/omniauth/strategies/hackid.rb', line 59 def build_access_token if access_token = request.params["access_token"] ::OAuth2::AccessToken.from_hash( client, {"access_token" => access_token}.update() ) elsif signed_request_contains_access_token? hash = signed_request.clone ::OAuth2::AccessToken.new( client, hash.delete('oauth_token'), hash.merge!(.merge(:expires_at => hash.delete('expires'))) ) else { super }.tap do |token| token..merge!() end end end |
#callback_url ⇒ Object
NOTE if we’re using code from the signed request then HackID sets the redirect_uri to ” during the authorize phase + it must match during the access_token phase: github.com/facebook/php-sdk/blob/master/src/base_facebook.php#L348
102 103 104 105 106 107 108 |
# File 'lib/omniauth/strategies/hackid.rb', line 102 def callback_url if @authorization_code_from_signed_request '' else [:callback_url] || super end end |
#raw_info ⇒ Object
55 56 57 |
# File 'lib/omniauth/strategies/hackid.rb', line 55 def raw_info @raw_info ||= access_token.get('/me').parsed || {} end |
#request_phase ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/omniauth/strategies/hackid.rb', line 79 def request_phase if signed_request_contains_access_token? # if we already have an access token, we can just hit the # callback URL directly and pass the signed request along params = { :signed_request => raw_signed_request } params[:state] = request.params['state'] if request.params['state'] query = Rack::Utils.build_query(params) url = callback_url url << "?" unless url.match(/\?/) url << "&" unless url.match(/[\&\?]$/) url << query redirect url else super end end |
#signed_request ⇒ Object
Parse signed request in order, from:
-
the request ‘signed_request’ param (server-side flow from canvas pages) or
-
a cookie (client-side flow via JS SDK)
142 143 144 145 |
# File 'lib/omniauth/strategies/hackid.rb', line 142 def signed_request @signed_request ||= raw_signed_request && parse_signed_request(raw_signed_request) end |