Class: JSONWebToken::Token
- Inherits:
-
Object
- Object
- JSONWebToken::Token
- Defined in:
- lib/json_web_token/token.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_NOT_BEFORE_TIME =
5
- DEFAULT_EXPIRE_TIME =
60
Instance Attribute Summary collapse
-
#audience ⇒ Object
Returns the value of attribute audience.
-
#expire_time ⇒ Object
Returns the value of attribute expire_time.
-
#id ⇒ Object
Returns the value of attribute id.
-
#issued_at ⇒ Object
Returns the value of attribute issued_at.
-
#issuer ⇒ Object
Returns the value of attribute issuer.
-
#not_before ⇒ Object
Returns the value of attribute not_before.
-
#subject ⇒ Object
Returns the value of attribute subject.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #encoded ⇒ Object
-
#initialize ⇒ Token
constructor
A new instance of Token.
- #payload ⇒ Object
Constructor Details
#initialize ⇒ Token
Returns a new instance of Token.
13 14 15 16 17 18 19 20 21 |
# File 'lib/json_web_token/token.rb', line 13 def initialize @id = SecureRandom.uuid @issued_at = Time.now # we give a few seconds for time shift @not_before = issued_at - DEFAULT_NOT_BEFORE_TIME # default 60 seconds should be more than enough for this authentication token @expire_time = issued_at + DEFAULT_EXPIRE_TIME @custom_payload = {} end |
Instance Attribute Details
#audience ⇒ Object
Returns the value of attribute audience.
7 8 9 |
# File 'lib/json_web_token/token.rb', line 7 def audience @audience end |
#expire_time ⇒ Object
Returns the value of attribute expire_time.
8 9 10 |
# File 'lib/json_web_token/token.rb', line 8 def expire_time @expire_time end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/json_web_token/token.rb', line 7 def id @id end |
#issued_at ⇒ Object
Returns the value of attribute issued_at.
8 9 10 |
# File 'lib/json_web_token/token.rb', line 8 def issued_at @issued_at end |
#issuer ⇒ Object
Returns the value of attribute issuer.
7 8 9 |
# File 'lib/json_web_token/token.rb', line 7 def issuer @issuer end |
#not_before ⇒ Object
Returns the value of attribute not_before.
8 9 10 |
# File 'lib/json_web_token/token.rb', line 8 def not_before @not_before end |
#subject ⇒ Object
Returns the value of attribute subject.
7 8 9 |
# File 'lib/json_web_token/token.rb', line 7 def subject @subject end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 |
# File 'lib/json_web_token/token.rb', line 23 def [](key) @custom_payload[key] end |
#[]=(key, value) ⇒ Object
27 28 29 |
# File 'lib/json_web_token/token.rb', line 27 def []=(key, value) @custom_payload[key] = value end |
#encoded ⇒ Object
31 32 33 |
# File 'lib/json_web_token/token.rb', line 31 def encoded raise NotImplementedError end |
#payload ⇒ Object
35 36 37 38 39 |
# File 'lib/json_web_token/token.rb', line 35 def payload predefined_claims .merge(@custom_payload) .merge(default_payload) end |