Class: JWTea::Token::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/jw_tea/token/payload.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/jw_tea/token/payload.rb', line 7

def data
  @data
end

#expObject (readonly)

Returns the value of attribute exp.



7
8
9
# File 'lib/jw_tea/token/payload.rb', line 7

def exp
  @exp
end

#iatObject (readonly)

Returns the value of attribute iat.



7
8
9
# File 'lib/jw_tea/token/payload.rb', line 7

def iat
  @iat
end

#jtiObject (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_hObject



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