Class: Core::Models::OAuth::AccessToken

Inherits:
Object
  • Object
show all
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.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorizationCore::Models::OAuth::Authorization

Returns the authorization code that issued this token to the application for this user.

Returns:



22
# File 'lib/core/models/oauth/access_token.rb', line 22

belongs_to :authorization, class_name: 'Core::Models::OAuth::Authorization', inverse_of: :tokens

#expirationInteger

Returns the time, in seconds, after which the token is declared expired, and thus can't be used anymore.

Returns:

  • (Integer)

    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

#valueString

Returns the value of the token, returned to the application when built.

Returns:

  • (String)

    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

Returns:

  • (Boolean)

    TRUE if the token is expired, FALSE otherwise.



30
31
32
# File 'lib/core/models/oauth/access_token.rb', line 30

def expired?
  created_at.to_time.to_i + expiration < Time.now.to_i
end