Class: JWT::Decode
- Inherits:
-
Object
- Object
- JWT::Decode
- Defined in:
- lib/jwt/decode.rb
Overview
Decoding logic for JWT
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
Class Method Summary collapse
Instance Method Summary collapse
- #decode_segments ⇒ Object
-
#initialize(jwt, key, verify, options, &keyfinder) ⇒ Decode
constructor
A new instance of Decode.
- #verify ⇒ Object
Constructor Details
#initialize(jwt, key, verify, options, &keyfinder) ⇒ Decode
Returns a new instance of Decode.
13 14 15 16 17 18 19 |
# File 'lib/jwt/decode.rb', line 13 def initialize(jwt, key, verify, , &keyfinder) @jwt = jwt @key = key @verify = verify @options = @keyfinder = keyfinder end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
11 12 13 |
# File 'lib/jwt/decode.rb', line 11 def header @header end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
11 12 13 |
# File 'lib/jwt/decode.rb', line 11 def payload @payload end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
11 12 13 |
# File 'lib/jwt/decode.rb', line 11 def signature @signature end |
Class Method Details
.base64url_decode(str) ⇒ Object
44 45 46 47 |
# File 'lib/jwt/decode.rb', line 44 def self.base64url_decode(str) str += '=' * (4 - str.length.modulo(4)) Base64.decode64(str.tr('-_', '+/')) end |
Instance Method Details
#decode_segments ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/jwt/decode.rb', line 21 def decode_segments header_segment, payload_segment, crypto_segment = raw_segments(@jwt, @verify) @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 |
#verify ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/jwt/decode.rb', line 49 def verify @options.each do |key, val| next unless key.to_s =~ /verify/ Verify.send(key, payload, @options) if val end end |