PyJWT >= 1.5.1 exception fixed #377
Merged
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.
Hello. I took the time to trace the following error (caused with PyJWT >= 1.5.1).
This is the same error that resulted in this being committed.
I was able to find out the cause for the exception raised, and fix the test.
But you should verify that works for you, as I didn't check how it fits into your package.
Also, this fix is probably not backwards compatible for PyJWT.As I don't use PyJWT, I can't really come up with that myself easily.
All I can come up with is checking pyjwt's version and deciding what call arguments to use according to that.
Edit: So, it is backwards compatible :)
Disclaimer: I don't actually use twilio or this package. Just thought this might help.
Original test error:
Call stack:
Click to expand/collapse call stack
JwtTest.test_decode_allows_skip_verification
intests/unit/jwt/test_jwt.py
:source
Jwt.from_jwt
intwilio/jwt/__init__.py
:source
PyJWT.decode
in<pyjwt>/api_jwt.py
:source
PyJWS.decode
in<pyjwt>/api_jws.py
:source
PyJWS._verify_signature
in<pyjwt>/api_jws.py
:source
HMACAlgorithm(HMACAlgorithm.SHA256).prepare_key
in<pyjwt>/algorithms.py
:source
force_bytes
in<pyjwt>/utils.py
:source
key
isNone
, it raises the exception.Solution:
Now, it seems the verify argument usage has changed in the latest version, in a way that is not backwards compatible, as can be seen in the following diff for PyJWT:
source
verify
doesn't actually get passed.Its value is set into
8000 verify_signature
in options, but only ifoptions
isNone
or ifoptions
doesn't haveverify_signature
in it (seeoptions.setdefault
line)Jwt.from_jwt
setsoptions
, and that's whyverify
wasn't being honoured inPyJWT.decode
.And so, by modifying the code as suggested in this PR, I was able to get the failing test to pass.
Hope this helps you solve the issues :)