2018-11-08 04:28:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'jwt'
|
|
|
|
|
|
|
|
module JSONWebToken
|
|
|
|
class HMACToken < Token
|
|
|
|
IAT_LEEWAY = 60
|
|
|
|
JWT_ALGORITHM = 'HS256'
|
|
|
|
|
|
|
|
def initialize(secret)
|
|
|
|
super()
|
|
|
|
|
|
|
|
@secret = secret
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def encoded
|
2018-12-29 03:07:45 -05:00
|
|
|
JWT.encode(payload, secret, JWT_ALGORITHM, { typ: 'JWT' })
|
2018-11-08 04:28:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :secret
|
|
|
|
end
|
|
|
|
end
|