Class: OmniAuth::Strategies::GoogleOauth2

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

Constant Summary collapse

BASE_SCOPE_URL =
"https://www.googleapis.com/auth/"
DEFAULT_SCOPE =
"userinfo.email,userinfo.profile"

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/omniauth/strategies/google_oauth2.rb', line 21

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

    raw_scope = params[:scope] || DEFAULT_SCOPE
    scope_list = raw_scope.split(" ").map {|item| item.split(",")}.flatten
    scope_list.map! { |s| s =~ /^https?:\/\// ? s : "#{BASE_SCOPE_URL}#{s}" }
    params[:scope] = scope_list.join(" ")
    params[:access_type] = 'offline' if params[:access_type].nil?

    session['omniauth.state'] = params[:state] if params['state']
  end
end

#custom_build_access_tokenObject Also known as: build_access_token



68
69
70
71
72
73
74
# File 'lib/omniauth/strategies/google_oauth2.rb', line 68

def custom_build_access_token
  if verify_token(request.params['id_token'], request.params['access_token'])
    ::OAuth2::AccessToken.from_hash(client, request.params.dup)
  else
    orig_build_access_token
  end
end

#raw_friend_info(id) ⇒ Object



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

def raw_friend_info(id)
  @raw_friend_info ||= access_token.get("https://www.googleapis.com/plus/v1/people/#{id}/people/visible").parsed
end

#raw_infoObject



60
61
62
# File 'lib/omniauth/strategies/google_oauth2.rb', line 60

def raw_info
  @raw_info ||= access_token.get('https://www.googleapis.com/oauth2/v1/userinfo').parsed
end