Class: SolidusJwt::Token

Inherits:
BaseRecord show all
Defined in:
app/models/solidus_jwt/token.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRecord

table_name_prefix

Class Method Details

.honor?(token) ⇒ Boolean

Whether to honor a token or not.

Returns:

  • (Boolean)


42
43
44
# File 'app/models/solidus_jwt/token.rb', line 42

def self.honor?(token)
  non_expired.where(active: true).find_by(token: token).present?
end

.invalidate(user) ⇒ Object

Set all non expired refresh tokens to inactive



30
31
32
33
34
35
36
# File 'app/models/solidus_jwt/token.rb', line 30

def self.invalidate(user)
  # rubocop:disable Rails/SkipsModelValidations
  non_expired.
    where(user_id: user.to_param).
    update_all(active: false)
  # rubocop:enable Rails/SkipsModelValidations
end

Instance Method Details

#expired?Boolean

Whether the token is expired

Returns:

  • (Boolean)

    If the token is older than the configured refresh expiration amount then will be true. Otherwise false.



59
60
61
# File 'app/models/solidus_jwt/token.rb', line 59

def expired?
  created_at < SolidusJwt::Config.refresh_expiration.seconds.ago
end

#honor?Boolean

Whether the token should be honored.

Returns:

  • (Boolean)

    Will be true if the token is active and not expired. Otherwise false.



50
51
52
# File 'app/models/solidus_jwt/token.rb', line 50

def honor?
  active? && !expired?
end