Class: JWTea::Token

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

Defined Under Namespace

Classes: Payload

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Token

Returns a new instance of Token.



24
25
26
# File 'lib/jw_tea/token.rb', line 24

def initialize(payload)
  @payload = JWTea::Token::Payload.from_hash(payload)
end

Instance Attribute Details

#encodedObject

Returns the value of attribute encoded.



20
21
22
# File 'lib/jw_tea/token.rb', line 20

def encoded
  @encoded
end

#payloadObject (readonly)

Returns the value of attribute payload.



21
22
23
# File 'lib/jw_tea/token.rb', line 21

def payload
  @payload
end

Class Method Details

.build(data, exp, secret, algorithm) ⇒ Object



13
14
15
16
17
# File 'lib/jw_tea/token.rb', line 13

def build(data, exp, secret, algorithm)
  token = new(data: data, exp: exp)
  token.encoded = ::JWT.encode(token.payload.to_h, secret, algorithm)
  token
end

.load(encoded_token, secret, algorithm) ⇒ Object



8
9
10
11
# File 'lib/jw_tea/token.rb', line 8

def load(encoded_token, secret, algorithm)
  payload, _header = ::JWT.decode(encoded_token, secret, true, verify_iat: true, algorithm: algorithm)
  new(payload)
end

Instance Method Details

#inspectObject

Prevent sentitive data from being accidentally logged to console



29
30
31
# File 'lib/jw_tea/token.rb', line 29

def inspect
  to_s
end