Class: JWT::NestedToken
Overview
Represents a Nested JWT as defined in RFC 7519 Section 5.2, Section 7.1 Step 5, and Appendix A.2.
A Nested JWT wraps an existing JWT string as the payload of another signed JWT.
Instance Attribute Summary
Attributes inherited from Token
Instance Method Summary collapse
-
#encoded_payload ⇒ Object
The payload of an outer JWS is the compact inner JWT itself.
-
#initialize(jwt) ⇒ NestedToken
constructor
A new instance of NestedToken.
- #sign!(algorithm:, key:, header: {}) ⇒ Object
Methods inherited from Token
#claim_errors, #detach_payload!, #encoded_header, #encoded_signature, #jwt, #signature, #signing_input, #valid_claims?, #verify_claims!
Constructor Details
#initialize(jwt) ⇒ NestedToken
Returns a new instance of NestedToken.
17 18 19 20 21 |
# File 'lib/jwt/nested_token.rb', line 17 def initialize(jwt) raise ArgumentError, 'Provided JWT must be a String' unless jwt.is_a?(String) super(payload: jwt, header: { 'cty' => 'JWT' }) end |
Instance Method Details
#encoded_payload ⇒ Object
The payload of an outer JWS is the compact inner JWT itself.
24 25 26 |
# File 'lib/jwt/nested_token.rb', line 24 def encoded_payload @encoded_payload ||= ::JWT::Base64.url_encode(payload) end |
#sign!(algorithm:, key:, header: {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jwt/nested_token.rb', line 28 def sign!(algorithm:, key:, header: {}) original_header = @header unless @signature @header = original_header.merge((header || {}).transform_keys(&:to_s)).merge('cty' => 'JWT') raise JWT::EncodeError, 'Nested JWT payload must be base64url-encoded' if @header['b64'] == false @encoded_header = @signing_input = nil end super(algorithm: algorithm, key: key) ensure unless @signature @header = original_header @encoded_header = @signing_input = nil end end |