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/"
BASE_SCOPES =
%w[profile email openid]
DEFAULT_SCOPE =
"email,profile"

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



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

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?:\/\// || BASE_SCOPES.include?(s) ? 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



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/omniauth/strategies/google_oauth2.rb', line 69

def custom_build_access_token
  if request.xhr? && request.params['code']
    verifier = request.params['code']
    client.auth_code.get_token(verifier, { :redirect_uri => 'postmessage'}.merge(token_params.to_hash(:symbolize_keys => true)),
                               deep_symbolize(options.auth_token_params || {}))
  elsif 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



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

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



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

def raw_info
  @raw_info ||= access_token.get('https://www.googleapis.com/plus/v1/people/me/openIdConnect').parsed
end