Class: JWTea::Token::Payload
- Inherits:
-
Object
- Object
- JWTea::Token::Payload
- 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.
15 16 17 18 19 20 |
# File 'lib/jw_tea/token/payload.rb', line 15 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.
7 8 9 |
# File 'lib/jw_tea/token/payload.rb', line 7 def data @data end |
#exp ⇒ Object (readonly)
Returns the value of attribute exp.
7 8 9 |
# File 'lib/jw_tea/token/payload.rb', line 7 def exp @exp end |
#iat ⇒ Object (readonly)
Returns the value of attribute iat.
7 8 9 |
# File 'lib/jw_tea/token/payload.rb', line 7 def iat @iat end |
#jti ⇒ Object (readonly)
Returns the value of attribute jti.
7 8 9 |
# File 'lib/jw_tea/token/payload.rb', line 7 def jti @jti end |
Class Method Details
.from_hash(payload_hash) ⇒ Object
10 11 12 |
# File 'lib/jw_tea/token/payload.rb', line 10 def from_hash(payload_hash) new(payload_hash.transform_keys(&:to_sym)) end |
Instance Method Details
#to_h ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/jw_tea/token/payload.rb', line 22 def to_h { 'data' => @data, 'jti' => @jti, 'iat' => @iat, 'exp' => @exp, } end |