Class: OmniAuth::Strategies::Bungie
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Bungie
- Defined in:
- lib/omniauth/strategies/bungie.rb
Instance Method Summary collapse
-
#callback_phase ⇒ Object
Updated callback phase with new refreshing.
-
#client ⇒ Object
Update client with Faraday middleware & special authorize url.
- #merge_stack(stack) ⇒ Object
-
#origin ⇒ Object
Defining of Origin string.
- #raw_info ⇒ Object
-
#token_params ⇒ Object
Token params with X-Api-Key & Origin.
Instance Method Details
#callback_phase ⇒ Object
Updated callback phase with new refreshing
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/omniauth/strategies/bungie.rb', line 37 def callback_phase error = request.params["error_reason"] || request.params["error"] if error fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"])) elsif !.provider_ignores_state && (request.params["state"].to_s.empty? || request.params["state"] != session.delete("omniauth.state")) fail!(:csrf_detected, CallbackError.new(:csrf_detected, "CSRF detected")) else self.access_token = build_access_token self.access_token = access_token.refresh!(token_params) if access_token.expired? env['omniauth.auth'] = auth_hash call_app! end rescue ::OAuth2::Error, CallbackError => e fail!(:invalid_credentials, e) rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e fail!(:timeout, e) rescue ::SocketError => e fail!(:failed_to_connect, e) end |
#client ⇒ Object
Update client with Faraday middleware & special authorize url.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/omniauth/strategies/bungie.rb', line 17 def client = { :authorize_url => .auth_url }.merge(.) ::OAuth2::BungieClient.new(nil, nil, deep_symbolize()) do |b| b.request :json b.adapter Faraday.default_adapter end end |
#merge_stack(stack) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/omniauth/strategies/bungie.rb', line 29 def merge_stack(stack) stack.inject({}) do |a, e| a.merge!(e) unless e.nil? a end end |
#origin ⇒ Object
Defining of Origin string
61 62 63 64 65 66 67 68 69 |
# File 'lib/omniauth/strategies/bungie.rb', line 61 def origin if .origin === true request.base_url elsif .origin.is_a? String .origin else '' end end |
#raw_info ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/omniauth/strategies/bungie.rb', line 107 def raw_info return @raw_info unless @raw_info.nil? @raw_info = access_token.get( '/Platform/User/GetCurrentBungieAccount/', token_params ).parsed @raw_info = @raw_info.dig('Response') end |
#token_params ⇒ Object
Token params with X-Api-Key & Origin
72 73 74 75 76 77 78 79 80 |
# File 'lib/omniauth/strategies/bungie.rb', line 72 def token_params token_params = .token_params.merge(("token")) token_params[:headers] ||= {} token_params[:headers]['X-Api-Key'] = .api_key token_params[:headers]['Origin'] = origin unless .origin.nil? token_params end |