Class: OmniAuth::Strategies::GooglePlus

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

Constant Summary collapse

DEFAULT_SCOPE =
"userinfo.email,plus.login"

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/omniauth/strategies/googleplus.rb', line 18

def authorize_params
  base_scope_url = "https://www.googleapis.com/auth/"
  
  super.tap do |params|
    # Read the params if passed directly to omniauth_authorize_path
    %w(scope approval_prompt access_type state hd user_id request_visible_actions).each do |k|
      params[k.to_sym] = request.params[k] unless [nil, ''].include?(request.params[k])
    end
    scopes = (params[:scope] || DEFAULT_SCOPE).split(",")
    scopes.map! { |s| s =~ /^https?:\/\// ? s : "#{base_scope_url}#{s}" }
    params[:scope] = scopes.join(' ')

    # Override the state per request
    session['omniauth.state'] = params[:state] if request.params['state']
  end
end

#email_infoObject



58
59
60
# File 'lib/omniauth/strategies/googleplus.rb', line 58

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

#locationObject



62
63
64
# File 'lib/omniauth/strategies/googleplus.rb', line 62

def location
  raw_info['currentLocation'] || raw_info['placesLived'].select { |place| place.has_key?('primary') }.first['value'] rescue nil
end

#raw_infoObject



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

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