Class: SimpleGoogleAuth::OAuth
- Inherits:
-
Object
- Object
- SimpleGoogleAuth::OAuth
- Defined in:
- lib/simple_google_auth/oauth.rb
Instance Method Summary collapse
- #exchange_code_for_auth_token!(code) ⇒ Object
-
#initialize(config) ⇒ OAuth
constructor
A new instance of OAuth.
- #refresh_auth_token!(refresh_token) ⇒ Object
Constructor Details
#initialize(config) ⇒ OAuth
Returns a new instance of OAuth.
3 4 5 6 7 8 9 10 |
# File 'lib/simple_google_auth/oauth.rb', line 3 def initialize(config) @config = config @client = HttpClient.new( @config.google_token_url, open_timeout: config.open_timeout, read_timeout: config.read_timeout ) end |
Instance Method Details
#exchange_code_for_auth_token!(code) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/simple_google_auth/oauth.rb', line 12 def exchange_code_for_auth_token!(code) response = @client.request( code: code, grant_type: "authorization_code", client_id: @config.client_id, client_secret: @config.client_secret, redirect_uri: @config.redirect_uri) parse_auth_response(response) end |
#refresh_auth_token!(refresh_token) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/simple_google_auth/oauth.rb', line 23 def refresh_auth_token!(refresh_token) return if refresh_token.blank? response = @client.request( refresh_token: refresh_token, client_id: @config.client_id, client_secret: @config.client_secret, grant_type: "refresh_token") response["refresh_token"] ||= refresh_token parse_auth_response(response) end |