Class: JWT::Auth::Token
- Inherits:
-
Object
- Object
- JWT::Auth::Token
- Defined in:
- lib/jwt/auth/token.rb
Overview
In-memory representation of JWT
Instance Attribute Summary collapse
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#subject ⇒ Object
Returns the value of attribute subject.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#expiration ⇒ Object
Returns the value of attribute expiration.
13 14 15 |
# File 'lib/jwt/auth/token.rb', line 13 def expiration @expiration end |
#subject ⇒ Object
Returns the value of attribute subject.
13 14 15 |
# File 'lib/jwt/auth/token.rb', line 13 def subject @subject end |
Class Method Details
.from_token(token) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/jwt/auth/token.rb', line 39 def self.from_token(token) payload = JWT.decode(token, JWT::Auth.secret).first token = JWT::Auth::Token.new token.expiration = payload['exp'] token.subject = JWT::Auth.model.find_by :id => payload['sub'], :token_version => payload['ver'] token end |
Instance Method Details
#renew! ⇒ Object
19 20 21 |
# File 'lib/jwt/auth/token.rb', line 19 def renew! self.expiration = nil end |
#to_jwt ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/jwt/auth/token.rb', line 23 def to_jwt payload = { :exp => expiration || JWT::Auth.token_lifetime.from_now.to_i, :sub => subject.id, :ver => subject.token_version } JWT.encode payload, JWT::Auth.secret end |
#valid? ⇒ Boolean
15 16 17 |
# File 'lib/jwt/auth/token.rb', line 15 def valid? subject && Time.at(expiration).future? end |