Class: Lionel::GoogleAuthentication
- Inherits:
-
Object
- Object
- Lionel::GoogleAuthentication
show all
- Includes:
- Configurable
- Defined in:
- lib/lionel/google_authentication.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#configuration, #configured?, included, #save_configuration
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
5
6
7
|
# File 'lib/lionel/google_authentication.rb', line 5
def access_token
@access_token
end
|
#client ⇒ Object
45
46
47
48
49
50
|
# File 'lib/lionel/google_authentication.rb', line 45
def client
@client ||= OAuth2::Client.new(google_client_id, google_client_secret,
:site => "https://accounts.google.com",
:token_url => "/o/oauth2/token",
:authorize_url => "/o/oauth2/auth")
end
|
Instance Method Details
#api_console_url ⇒ Object
41
42
43
|
# File 'lib/lionel/google_authentication.rb', line 41
def api_console_url
"https://code.google.com/apis/console"
end
|
#authorize_url ⇒ Object
34
35
36
37
38
39
|
# File 'lib/lionel/google_authentication.rb', line 34
def authorize_url
client.auth_code.authorize_url(
:redirect_uri => "urn:ietf:wg:oauth:2.0:oob",
:scope => scopes.join(' ')
)
end
|
#data ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/lionel/google_authentication.rb', line 9
def data
raise "No access token" unless access_token
{
google_token: access_token.token,
google_refresh_token: access_token.refresh_token,
google_client_id: google_client_id,
google_client_secret: google_client_secret
}
end
|
#refresh ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/lionel/google_authentication.rb', line 24
def refresh
return false unless refresh_token
current_token = OAuth2::AccessToken.from_hash(client,
:refresh_token => refresh_token,
:expires_in => one_year
)
@access_token = current_token.refresh! end
|
#retrieve_access_token(authorization_code) ⇒ Object
19
20
21
22
|
# File 'lib/lionel/google_authentication.rb', line 19
def retrieve_access_token(authorization_code)
@access_token = client.auth_code.get_token(authorization_code,
:redirect_uri => "urn:ietf:wg:oauth:2.0:oob")
end
|