Module: Google::OAuth
- Defined in:
- lib/TheresNoBox/google.rb
Class Method Summary collapse
- .authentication_url(scopes = ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/analytics.readonly']) ⇒ Object
- .get_token(code) ⇒ Object
Class Method Details
.authentication_url(scopes = ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/analytics.readonly']) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/TheresNoBox/google.rb', line 35 def self.authentication_url( scopes = ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/analytics.readonly']) url = 'https://accounts.google.com/o/oauth2/auth?' url << 'access_type=online' url << '&approval_prompt=auto' url << "&client_id=#{Settings.googleClientId}" url << "&redirect_uri=#{Settings.accountUrl}/auth/google/callback" url << '&response_type=code' url << "&scope=#{scopes.join('%20')}" return url end |
.get_token(code) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/TheresNoBox/google.rb', line 48 def self.get_token(code) data = { :code=>code, :client_id=>Settings.googleClientId, :client_secret=>Settings.googleClientSecret, :redirect_uri=>"#{Settings.accountUrl}/auth/google/callback", :grant_type=>'authorization_code' } return JSON.parse( RestClient.post 'https://accounts.google.com/o/oauth2/token' , data)['access_token'] end |