class JWTEasy::Decoder
Decoder
object for decoding tokens.
-
This is usually not instantiated directly, but rather by way of calling
JWTEasy.decode
.
Attributes
configuration[R]
token[R]
Public Class Methods
new(token, configuration = nil)
click to toggle source
Initializes a new encoder instance.
-
If no configuration object is passed or is
nil
, the value ofJWTEasy.configuration
is used as the configuration object
@param [String] token the token to be decoded @param [Configuration] configuration the configuration object
# File lib/jwt_easy/decoder.rb, line 19 def initialize(token, configuration = nil) @token = token @configuration = configuration || JWTEasy.configuration @headers = {} end
Public Instance Methods
decode()
click to toggle source
Decodes the token with the configured options.
@return [Result] the result of the decoding
# File lib/jwt_easy/decoder.rb, line 28 def decode Result.new(*JWT.decode(token, configuration.secret, verification?, headers)) end
headers()
click to toggle source
Determines the headers to be used during decoding.
@return [Hash] the headers to be used
# File lib/jwt_easy/decoder.rb, line 42 def headers @headers.tap do |headers| headers[:algorithm] = configuration.algorithm if verification? case configuration.claim when CLAIM_EXPIRATION_TIME headers.merge!(exp_headers) when CLAIM_NOT_BEFORE_TIME headers.merge!(nbf_headers) end end end
verification?()
click to toggle source
Determines if verification will be used during decoding.
@return [Boolean] if verification will be used or not
# File lib/jwt_easy/decoder.rb, line 35 def verification? configuration.secret.nil? == false end
Private Instance Methods
exp_headers()
click to toggle source
# File lib/jwt_easy/decoder.rb, line 56 def exp_headers {}.tap do |headers| headers[:validate_exp] = true headers[:exp_leeway] = configuration.leeway if configuration.leeway end end
nbf_headers()
click to toggle source
# File lib/jwt_easy/decoder.rb, line 63 def nbf_headers {}.tap do |headers| headers[:validate_nbf] = true headers[:nbf_leeway] = configuration.leeway if configuration.leeway end end