Class: JSONWebToken::HMACToken

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

Constant Summary collapse

IAT_LEEWAY =
60
JWT_ALGORITHM =
'HS256'

Constants inherited from Token

Token::DEFAULT_EXPIRE_TIME, Token::DEFAULT_NOT_BEFORE_TIME

Instance Attribute Summary

Attributes inherited from Token

#audience, #expire_time, #id, #issued_at, #issuer, #not_before, #subject

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Token

#[], #[]=, #payload

Constructor Details

#initialize(secret) ⇒ HMACToken

Returns a new instance of HMACToken.


10
11
12
13
14
# File 'lib/json_web_token/hmac_token.rb', line 10

def initialize(secret)
  super()

  @secret = secret
end

Class Method Details

.decode(token, secret, leeway: IAT_LEEWAY, verify_iat: true) ⇒ Object


16
17
18
# File 'lib/json_web_token/hmac_token.rb', line 16

def self.decode(token, secret, leeway: IAT_LEEWAY, verify_iat: true)
  JWT.decode(token, secret, true, leeway: leeway, verify_iat: verify_iat, algorithm: JWT_ALGORITHM)
end

Instance Method Details

#encodedObject


20
21
22
# File 'lib/json_web_token/hmac_token.rb', line 20

def encoded
  JWT.encode(payload, secret, JWT_ALGORITHM, { typ: 'JWT' })
end