Class: JWT::Decode

Inherits:
Object
  • Object
show all
Defined in:
lib/jwt/decode.rb

Overview

Decoding logic for JWT

Instance Method Summary collapse

Constructor Details

#initialize(jwt, key, verify, options, &keyfinder) ⇒ Decode

Returns a new instance of Decode.

Raises:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jwt/decode.rb', line 10

def initialize(jwt, key, verify, options, &keyfinder)
  raise JWT::DecodeError, 'Nil JSON web token' unless jwt

  @jwt = jwt
  @key = key
  @options = options
  @segments = jwt.split('.')
  @verify = verify
  @signature = ''
  @keyfinder = keyfinder
end

Instance Method Details

#decode_segmentsObject

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jwt/decode.rb', line 22

def decode_segments
  validate_segment_count!
  if @verify
    decode_signature
    verify_algo
    set_key
    verify_signature
    verify_claims
  end
  raise JWT::DecodeError, 'Not enough or too many segments' unless header && payload

  [payload, header]
end