Class: OmniAuth::Strategies::Bungie

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/bungie.rb

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject

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 !options.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

#clientObject

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
  client_options = {
    :authorize_url => options.auth_url
  }.merge(options.client_options)

  ::OAuth2::BungieClient.new(nil, nil, deep_symbolize(client_options)) 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

#originObject

Defining of Origin string



61
62
63
64
65
66
67
68
69
# File 'lib/omniauth/strategies/bungie.rb', line 61

def origin
  if options.origin === true
    request.base_url
  elsif options.origin.is_a? String
    options.origin
  else
    ''
  end
end

#raw_infoObject



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_paramsObject

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 = options.token_params.merge(options_for("token"))

  token_params[:headers] ||= {}
  token_params[:headers]['X-Api-Key'] = options.api_key
  token_params[:headers]['Origin'] = origin unless options.origin.nil?

  token_params
end