Class: Core::Models::OAuth::AccessToken
- Inherits:
-
Object
- Object
- Core::Models::OAuth::AccessToken
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/core/models/oauth/access_token.rb
Overview
An access token is the value assigned to the application to access the data the user is allowed to access.
Instance Attribute Summary collapse
-
#authorization ⇒ Core::Models::OAuth::Authorization
The authorization code that issued this token to the application for this user.
-
#expiration ⇒ Integer
The time, in seconds, after which the token is declared expired, and thus can’t be used anymore.
-
#refresh_token ⇒ Core::Models::OAuth::RefreshToken
readonly
The refresh token linked to this token.
-
#value ⇒ String
The value of the token, returned to the application when built.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Checks if the current date is inferior to the creation date + expiration period.
- #premium? ⇒ Boolean
-
#scopes ⇒ Array<Core::Models::OAuth::Scope>
Returns the scopes this access token can use to access the application.
Instance Attribute Details
#authorization ⇒ Core::Models::OAuth::Authorization
Returns the authorization code that issued this token to the application for this user.
22 |
# File 'lib/core/models/oauth/access_token.rb', line 22 belongs_to :authorization, class_name: 'Core::Models::OAuth::Authorization', inverse_of: :tokens |
#expiration ⇒ Integer
Returns the time, in seconds, after which the token is declared expired, and thus can’t be used anymore.
18 |
# File 'lib/core/models/oauth/access_token.rb', line 18 field :expiration, type: Integer, default: 86400 |
#refresh_token ⇒ Core::Models::OAuth::RefreshToken (readonly)
Returns the refresh token linked to this token.
28 |
# File 'lib/core/models/oauth/access_token.rb', line 28 has_one :refresh_token, class_name: 'Core::Models::OAuth::RefreshToken', inverse_of: :token |
#value ⇒ String
Returns the value of the token, returned to the application when built.
15 |
# File 'lib/core/models/oauth/access_token.rb', line 15 field :value, type: String, default: ->{ SecureRandom.hex } |
Instance Method Details
#expired? ⇒ Boolean
Checks if the current date is inferior to the creation date + expiration period
36 37 38 39 40 41 42 |
# File 'lib/core/models/oauth/access_token.rb', line 36 def expired? # Handles the case where the token is given to a premium app (our apps have infinite tokens). return false if premium? return true if refresh_token.used? created_at.to_time.to_i + expiration < Time.now.to_i end |
#premium? ⇒ Boolean
53 54 55 |
# File 'lib/core/models/oauth/access_token.rb', line 53 def premium? .application.premium end |
#scopes ⇒ Array<Core::Models::OAuth::Scope>
Returns the scopes this access token can use to access the application
46 47 48 49 50 51 |
# File 'lib/core/models/oauth/access_token.rb', line 46 def scopes # Premium applications (our applications) have all the rights on the API. return Core::Models::OAuth::Scope.all.to_a if premium? .scopes end |