Class: JWT::Decode

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

Overview

Decoding logic for JWT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jwt, verify) ⇒ Decode

Returns a new instance of Decode.



16
17
18
19
20
21
22
# File 'lib/jwt/decode.rb', line 16

def initialize(jwt, verify)
  @jwt = jwt
  @verify = verify
  @header = ''
  @payload = ''
  @signature = ''
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



9
10
11
# File 'lib/jwt/decode.rb', line 9

def header
  @header
end

#payloadObject (readonly)

Returns the value of attribute payload.



9
10
11
# File 'lib/jwt/decode.rb', line 9

def payload
  @payload
end

#signatureObject (readonly)

Returns the value of attribute signature.



9
10
11
# File 'lib/jwt/decode.rb', line 9

def signature
  @signature
end

Class Method Details

.base64url_decode(str) ⇒ Object



11
12
13
14
# File 'lib/jwt/decode.rb', line 11

def self.base64url_decode(str)
  str += '=' * (4 - str.length.modulo(4))
  Base64.decode64(str.tr('-_', '+/'))
end

Instance Method Details

#decode_segmentsObject



24
25
26
27
28
29
30
# File 'lib/jwt/decode.rb', line 24

def decode_segments
  header_segment, payload_segment, crypto_segment = raw_segments
  @header, @payload = decode_header_and_payload(header_segment, payload_segment)
  @signature = Decode.base64url_decode(crypto_segment.to_s) if @verify
  signing_input = [header_segment, payload_segment].join('.')
  [@header, @payload, @signature, signing_input]
end