feat: Feature parity for a_decode_token
and decode_token
#616
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I saw that the
decode_token
allows configuring theleeway
(introduced as part of #568), but the same feature is unavailable ina_decode_token
.In an attempt to bridge the gap between, I refactored out the logic to validate the token, leaving the functions only responsible for fetching the public key.
Also fix the case with using
validate=False
+ akey
resulting in the validation still being executed.There is a slight difference in the behaviour though, with regards to how
key=None
is handled:Before:
A call like
decode_token(token, validate=True, key=None)
would be considered "okay", but fail withjwcrypto.jws.InvalidJWSSignature: Verification failed for all signatures["Failed: [ValueError('Unrecognized key type')]"]
because the key wasNone
.With the new change:
The same call will fetch the public key and use it to validate the token.
I think it's an acceptable change in behaviour/API, as I doubt an exception was what consumers would want.