Class: OmniAuth::Strategies::Stackoverflow
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Stackoverflow
- Defined in:
- lib/omniauth/strategies/stackoverflow.rb
Defined Under Namespace
Classes: NoAuthorizationCodeError
Constant Summary collapse
- DEFAULT_SCOPE =
'email'
Instance Attribute Summary collapse
-
#oauth_key ⇒ Object
Returns the value of attribute oauth_key.
Instance Method Summary collapse
- #access_token_options ⇒ Object
-
#authorize_params ⇒ Object
You can pass
display,stateorscopeparams to the auth request, if you need to set them dynamically. - #build_access_token ⇒ Object
- #callback_phase ⇒ Object
-
#callback_url ⇒ Object
NOTE if we’re using code from the signed request then FB 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 Attribute Details
#oauth_key ⇒ Object
Returns the value of attribute oauth_key.
11 12 13 |
# File 'lib/omniauth/strategies/stackoverflow.rb', line 11 def oauth_key @oauth_key end |
Instance Method Details
#access_token_options ⇒ Object
108 109 110 |
# File 'lib/omniauth/strategies/stackoverflow.rb', line 108 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/facebook?display=popup&state=ABC
119 120 121 122 123 124 |
# File 'lib/omniauth/strategies/stackoverflow.rb', line 119 def super.tap do |params| %w[display state scope].each { |v| params[v.to_sym] = request.params[v] if request.params[v] } params[:scope] ||= DEFAULT_SCOPE end end |
#build_access_token ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/omniauth/strategies/stackoverflow.rb', line 53 def build_access_token if 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_phase ⇒ Object
91 92 93 94 95 |
# File 'lib/omniauth/strategies/stackoverflow.rb', line 91 def callback_phase @oauth_key = [:oauth_key] super end |
#callback_url ⇒ Object
NOTE if we’re using code from the signed request then FB 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
100 101 102 103 104 105 106 |
# File 'lib/omniauth/strategies/stackoverflow.rb', line 100 def callback_url if @authorization_code_from_signed_request '' else [:callback_url] || super end end |
#raw_info ⇒ Object
48 49 50 51 |
# File 'lib/omniauth/strategies/stackoverflow.rb', line 48 def raw_info access_token.client.site = "https://api.stackexchange.com" @raw_info ||= access_token.get('/2.0/me', :params => { 'site' => 'stackoverflow', 'access_token' => access_token.token, 'key' => @oauth_key }).parsed["items"].first || {} end |
#request_phase ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/omniauth/strategies/stackoverflow.rb', line 70 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)
132 133 134 135 |
# File 'lib/omniauth/strategies/stackoverflow.rb', line 132 def signed_request @signed_request ||= raw_signed_request && parse_signed_request(raw_signed_request) end |