Class: OmniAuth::Strategies::GoogleOAuth2
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::GoogleOAuth2
show all
- Defined in:
- lib/omniauth/strategies/google_oauth2.rb
Overview
OAuth 2.0 based authentication with Google.
Instance Attribute Summary
Attributes inherited from OAuth2
#client_id, #client_options, #client_secret, #options
Instance Method Summary
collapse
Methods inherited from OAuth2
#callback_url, #client
Constructor Details
#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ GoogleOAuth2
Returns a new instance of GoogleOAuth2.
12
13
14
15
16
17
18
19
20
|
# File 'lib/omniauth/strategies/google_oauth2.rb', line 12
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
client_options = {
:site => 'https://accounts.google.com',
:authorize_url => '/o/oauth2/auth',
:token_url => '/o/oauth2/token'
}
super(app, (options[:name] || :google_oauth2), client_id, client_secret, client_options, options, &block)
end
|
Instance Method Details
#auth_hash ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/omniauth/strategies/google_oauth2.rb', line 30
def auth_hash
OmniAuth::Utils.deep_merge(super, {
'uid' => user_info['uid'],
'user_info' => user_info,
'credentials' => {'expires_at' => @access_token.expires_at},
'extra' => {'user_hash' => user_data}
})
end
|
#request_phase ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/omniauth/strategies/google_oauth2.rb', line 22
def request_phase
google_email_scope = "www.googleapis.com/auth/userinfo.email"
options[:scope] ||= "https://#{google_email_scope}"
options[:scope] << " https://#{google_email_scope}" unless options[:scope] =~ %r[http[s]?:\/\/#{google_email_scope}]
redirect client.auth_code.authorize_url(
{:redirect_uri => callback_url, :response_type => "code"}.merge(options))
end
|
#user_data ⇒ Object
52
53
54
55
|
# File 'lib/omniauth/strategies/google_oauth2.rb', line 52
def user_data
@data ||=
@access_token.get("https://www.googleapis.com/userinfo/email?alt=json").parsed
end
|
#user_info ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/omniauth/strategies/google_oauth2.rb', line 39
def user_info
if user_data['data']['isVerified']
email = user_data['data']['email']
else
email = nil
end
{
'email' => email,
'uid' => email,
'name' => email
}
end
|