Class: JWTea::Token::Payload
- Inherits:
-
Object
- Object
- JWTea::Token::Payload
- Extended by:
- Forwardable
- Defined in:
- lib/jw_tea/token/payload.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#exp ⇒ Object
readonly
Returns the value of attribute exp.
-
#iat ⇒ Object
readonly
Returns the value of attribute iat.
-
#jti ⇒ Object
readonly
Returns the value of attribute jti.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data:, exp:, iat: nil, jti: nil) ⇒ Payload
constructor
A new instance of Payload.
- #to_h ⇒ Object
Constructor Details
#initialize(data:, exp:, iat: nil, jti: nil) ⇒ Payload
Returns a new instance of Payload.
19 20 21 22 23 24 |
# File 'lib/jw_tea/token/payload.rb', line 19 def initialize(data:, exp:, iat: nil, jti: nil) @data = data @exp = exp @iat = iat || Time.current.to_i @jti = jti || Digest::MD5.hexdigest([SecureRandom.hex, @iat].join(':')) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/jw_tea/token/payload.rb', line 8 def data @data end |
#exp ⇒ Object (readonly)
Returns the value of attribute exp.
8 9 10 |
# File 'lib/jw_tea/token/payload.rb', line 8 def exp @exp end |
#iat ⇒ Object (readonly)
Returns the value of attribute iat.
8 9 10 |
# File 'lib/jw_tea/token/payload.rb', line 8 def iat @iat end |
#jti ⇒ Object (readonly)
Returns the value of attribute jti.
8 9 10 |
# File 'lib/jw_tea/token/payload.rb', line 8 def jti @jti end |
Class Method Details
.from_hash(payload_hash) ⇒ Object
11 12 13 |
# File 'lib/jw_tea/token/payload.rb', line 11 def from_hash(payload_hash) new(payload_hash.transform_keys(&:to_sym)) end |
Instance Method Details
#to_h ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/jw_tea/token/payload.rb', line 26 def to_h { 'data' => @data, 'jti' => @jti, 'iat' => @iat, 'exp' => @exp, } end |