Module: Googol::Authenticable
- Includes:
- ClientTokens, Requestable
- Included in:
- GoogleAccount, YoutubeAccount
- Defined in:
- lib/googol/authenticable.rb
Overview
Provides methods to authenticate as an account (either Google or Youtube).
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#credentials ⇒ Hash
Return the authorization credentials of an account for this app.
-
#initialize(attrs = {}) ⇒ Object
Initialize an object with either an authorization code or a refresh token.
Methods included from Requestable
Methods included from ClientTokens
#client_id, client_id=, #client_secret, client_secret=
Instance Method Details
#credentials ⇒ Hash
Return the authorization credentials of an account for this app.
40 41 42 43 44 |
# File 'lib/googol/authenticable.rb', line 40 def credentials @credentials ||= request! method: :post, host: 'https://accounts.google.com', path: '/o/oauth2/token', body: credentials_params end |
#initialize(attrs = {}) ⇒ Object
Note:
The refresh token never expires but the access token expires after 1 hour. If the access token has expired, initialize the object again with the refresh token.
Initialize an object with either an authorization code or a refresh token
25 26 27 28 29 30 |
# File 'lib/googol/authenticable.rb', line 25 def initialize(attrs = {}) @code = attrs[:code] @refresh_token = attrs[:refresh_token] @credentials = {access_token: attrs[:access_token]} if attrs[:access_token] @redirect_url = attrs.fetch :redirect_url, 'http://example.com/' end |