Class: JWT::Auth::Token
- Inherits:
-
Object
- Object
- JWT::Auth::Token
- Defined in:
- lib/jwt/auth/token.rb
Overview
In-memory representation of JWT
Direct Known Subclasses
Instance Attribute Summary collapse
-
#issued_at ⇒ Object
Returns the value of attribute issued_at.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Token
constructor
A new instance of Token.
-
#lifetime ⇒ Object
Override this method in subclasses.
- #to_jwt ⇒ Object
-
#type ⇒ Object
Override this method in subclasses.
- #valid? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Token
Returns a new instance of Token.
15 16 17 |
# File 'lib/jwt/auth/token.rb', line 15 def initialize(params = {}) params.each { |key, value| send "#{key}=", value } end |
Instance Attribute Details
#issued_at ⇒ Object
Returns the value of attribute issued_at.
11 12 13 |
# File 'lib/jwt/auth/token.rb', line 11 def issued_at @issued_at end |
#subject ⇒ Object
Returns the value of attribute subject.
11 12 13 |
# File 'lib/jwt/auth/token.rb', line 11 def subject @subject end |
#version ⇒ Object
Returns the value of attribute version.
11 12 13 |
# File 'lib/jwt/auth/token.rb', line 11 def version @version end |
Class Method Details
Instance Method Details
#lifetime ⇒ Object
Override this method in subclasses
47 48 49 |
# File 'lib/jwt/auth/token.rb', line 47 def lifetime raise NotImplementedError end |
#to_jwt ⇒ Object
33 34 35 |
# File 'lib/jwt/auth/token.rb', line 33 def to_jwt JWT.encode payload, JWT::Auth.secret end |
#type ⇒ Object
Override this method in subclasses
40 41 42 |
# File 'lib/jwt/auth/token.rb', line 40 def type raise NotImplementedError end |
#valid? ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jwt/auth/token.rb', line 19 def valid? # Reload subject to prevent caching the old token_version subject&.reload return false if subject.nil? || issued_at.nil? || version.nil? return false if Time.at(issued_at + lifetime.to_i).past? return false if Time.at(issued_at).future? return false if version != subject.token_version true rescue ActiveRecord::RecordNotFound false end |