Class: JWTEasy::Decoder
- Inherits:
-
Object
- Object
- JWTEasy::Decoder
- Defined in:
- lib/jwt_easy/decoder.rb
Overview
Decoder object for decoding tokens.
-
This is usually not instantiated directly, but rather by way of calling
JWTEasy.decode
.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#decode ⇒ Result
Decodes the token with the configured options.
-
#headers ⇒ Hash
Determines the headers to be used during decoding.
-
#initialize(token, configuration = nil) ⇒ Decoder
constructor
Initializes a new encoder instance.
-
#verification? ⇒ Boolean
Determines if verification will be used during decoding.
Constructor Details
#initialize(token, configuration = nil) ⇒ Decoder
Initializes a new encoder instance.
-
If no configuration object is passed or is
nil
, the value ofJWTEasy.configuration
is used as the configuration object
19 20 21 22 23 |
# File 'lib/jwt_easy/decoder.rb', line 19 def initialize(token, configuration = nil) @token = token @configuration = configuration || JWTEasy.configuration @headers = {} end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
9 10 11 |
# File 'lib/jwt_easy/decoder.rb', line 9 def configuration @configuration end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/jwt_easy/decoder.rb', line 9 def token @token end |
Instance Method Details
#decode ⇒ Result
Decodes the token with the configured options.
28 29 30 |
# File 'lib/jwt_easy/decoder.rb', line 28 def decode Result.new(*JWT.decode(token, configuration.secret, verification?, headers)) end |
#headers ⇒ Hash
Determines the headers to be used during decoding.
42 43 44 45 46 47 48 49 50 51 52 |
# 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? ⇒ Boolean
Determines if verification will be used during decoding.
35 36 37 |
# File 'lib/jwt_easy/decoder.rb', line 35 def verification? configuration.secret.nil? == false end |