Class: JSONWebToken::Token

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

Direct Known Subclasses

HMACToken, RSAToken

Constant Summary collapse

DEFAULT_NOT_BEFORE_TIME =
5
DEFAULT_EXPIRE_TIME =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeToken

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

#audienceObject

Returns the value of attribute audience.



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

def audience
  @audience
end

#expire_timeObject

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

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#issued_atObject

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

#issuerObject

Returns the value of attribute issuer.



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

def issuer
  @issuer
end

#not_beforeObject

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

#subjectObject

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

#encodedObject

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/json_web_token/token.rb', line 31

def encoded
  raise NotImplementedError
end

#payloadObject



35
36
37
# File 'lib/json_web_token/token.rb', line 35

def payload
  @custom_payload.merge(default_payload)
end