Class: OmniAuth::Strategies::Goodgame

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

Constant Summary collapse

DEFAULT_SCOPE =
''

Instance Method Summary collapse

Instance Method Details

#access_token_optionsObject



66
67
68
69
70
# File 'lib/omniauth/strategies/goodgame.rb', line 66

def access_token_options
  options.access_token_options.each_with_object({}) do |(k, v), h|
    h[k.to_sym] = v
  end
end

#authorize_paramsObject



78
79
80
81
82
83
84
85
# File 'lib/omniauth/strategies/goodgame.rb', line 78

def authorize_params
  super.tap do |params|
    options[:authorize_options].each do |k|
      params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
    end
    params[:scope] = params[:scope] || DEFAULT_SCOPE
  end
end

#build_access_tokenObject



60
61
62
63
64
# File 'lib/omniauth/strategies/goodgame.rb', line 60

def build_access_token
  super.tap do |token|
    token.options.merge!(access_token_options)
  end
end

#callback_urlObject



72
73
74
75
76
# File 'lib/omniauth/strategies/goodgame.rb', line 72

def callback_url
  return options[:redirect_uri] unless options[:redirect_uri].nil?

  full_host + script_name + callback_path
end

#raw_infoObject



52
53
54
55
56
57
58
# File 'lib/omniauth/strategies/goodgame.rb', line 52

def raw_info
  id = access_token.get("https://goodgame.ru/api/4/users/@me2?access_token=#{access_token.token}",
                        headers: { 'Accept' => 'application/json' }).parsed.fetch('id')
  @raw_info =
    access_token.get("https://goodgame.ru/api/4/users/#{id}?access_token=#{access_token.token}",
                     headers: { 'Accept' => 'application/json' }).parsed
end

#request_phaseObject



21
22
23
24
25
# File 'lib/omniauth/strategies/goodgame.rb', line 21

def request_phase
  redirect client.auth_code
                 .authorize_url({ redirect_uri: callback_url }
                 .merge(authorize_params)).gsub(/%2[b,B]/, '+')
end