Class: OmniAuth::Strategies::Twitch

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

Constant Summary collapse

DEFAULT_SCOPE =
"user:read:email".freeze

Instance Method Summary collapse

Instance Method Details

#access_token_optionsObject



64
65
66
# File 'lib/omniauth/strategies/twitch.rb', line 64

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

#authorize_paramsObject



73
74
75
76
77
78
79
80
# File 'lib/omniauth/strategies/twitch.rb', line 73

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



58
59
60
61
62
# File 'lib/omniauth/strategies/twitch.rb', line 58

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

#callback_urlObject



68
69
70
71
# File 'lib/omniauth/strategies/twitch.rb', line 68

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
# File 'lib/omniauth/strategies/twitch.rb', line 52

def raw_info
  @raw_info ||=
    access_token.get("https://api.twitch.tv/helix/users").parsed.
    fetch("data").fetch(0)
end