Class: Yt::Models::Authentication
- Inherits:
-
Object
- Object
- Yt::Models::Authentication
- Defined in:
- lib/yt/models/authentication.rb
Overview
Provides methods to authenticate with YouTube (and Google) API.
Instance Attribute Summary collapse
-
#access_token ⇒ String
readonly
Before your application can access private data using a Google API, it must obtain an access token that grants access to that API.
-
#expires_at ⇒ Time
readonly
Access tokens have limited lifetimes.
-
#refresh_token ⇒ String
readonly
Access tokens have limited lifetimes.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Whether the access token has expired.
-
#initialize(data = {}) ⇒ Authentication
constructor
A new instance of Authentication.
-
#pending? ⇒ Boolean
Whether the device auth is pending.
Constructor Details
#initialize(data = {}) ⇒ Authentication
Returns a new instance of Authentication.
55 56 57 58 59 60 |
# File 'lib/yt/models/authentication.rb', line 55 def initialize(data = {}) @access_token = data['access_token'] @refresh_token = data['refresh_token'] @error = data['error'] @expires_at = expiration_date data.slice('expires_at', 'expires_in') end |
Instance Attribute Details
#access_token ⇒ String (readonly)
Before your application can access private data using a Google API, it must obtain an access token that grants access to that API.
A single access token can grant varying degrees of access to multiple APIs. A variable parameter called scope controls the set of resources and operations that an access token permits.
After an application obtains an access token, it sends the token to a Google API in an HTTP authorization header.
Access tokens are valid only for the set of operations and resources described in the scope of the token request. For example, if an access token is issued for the Google+ API, it does not grant access to the Google Contacts API.
23 24 25 |
# File 'lib/yt/models/authentication.rb', line 23 def access_token @access_token end |
#expires_at ⇒ Time (readonly)
Access tokens have limited lifetimes. If your application needs access to a Google API beyond the lifetime of a single access token, it can obtain a refresh token.
A refresh token allows your application to obtain new access tokens.
53 54 55 |
# File 'lib/yt/models/authentication.rb', line 53 def expires_at @expires_at end |
#refresh_token ⇒ String (readonly)
Access tokens have limited lifetimes. If your application needs access to a Google API beyond the lifetime of a single access token, it can obtain a refresh token. A refresh token allows your application to obtain new access tokens.
Save refresh tokens in secure long-term storage and continue to use them as long as they remain valid. Limits apply to the number of refresh tokens that are issued per client-user combination, and per user across all clients, and these limits are different. If your application requests enough refresh tokens to go over one of the limits, older refresh tokens stop working.
There is currently a 25-token limit per Google user account. If a user account has 25 valid tokens, the next authentication request succeeds, but quietly invalidates the oldest outstanding token without any user-visible warning.
43 44 45 |
# File 'lib/yt/models/authentication.rb', line 43 def refresh_token @refresh_token end |
Instance Method Details
#expired? ⇒ Boolean
Returns whether the access token has expired.
63 64 65 |
# File 'lib/yt/models/authentication.rb', line 63 def expired? @expires_at && @expires_at.past? end |
#pending? ⇒ Boolean
Returns whether the device auth is pending.
68 69 70 |
# File 'lib/yt/models/authentication.rb', line 68 def pending? @error == 'authorization_pending' end |