-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JWTIdentity raises common error JWTIdentityError #840
base: master
Are you sure you want to change the base?
Conversation
Seems like a sensible addition, though I'd note that the exception is not mentioned in the PyJWT documentation (except buried in a changelog), which probably limits the ability of other users to discover this. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #840 +/- ##
==========================================
+ Coverage 94.13% 94.17% +0.03%
==========================================
Files 11 11
Lines 597 618 +21
Branches 30 22 -8
==========================================
+ Hits 562 582 +20
- Misses 26 27 +1
Partials 9 9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
jwt will do a lot of checking at the payload level and may throw exceptions such as, InvalidSignatureError or ExpiredSignatureError. All exceptions are PyJWTError subclasses. I use a middleware to catch PyJWTError and send 401 HTTP response. This pull request allow to catch invalid authorization scheme with the same middleware. |
Yes, my point is that other users may struggle to figure this out, given it does not appear in the docs. Maybe worth a PR to that library as well to document it properly. |
The CI is failing, the mypy command did not succeed.
I can declare the
But it feels a bit tricky to me. I might have another solution. Currently, We can preserve this behavior by defining a def __getattr__(name: str) -> Any:
if name == "JWTIdentityPolicy":
try:
import jwt
except ImportError as error:
raise RuntimeError('Please install `PyJWT`') from error
from .jwt_identity import JWTIdentityPolicy
return JWTIdentityPolicy and remove try/except around Do you have a preference for the approach? |
I think it's probably fine as it is. I'll sort out the mypy errors later, just a little busy with other things right now. |
Hello,
What do these changes do?
All exceptions raised by the JWTIdentityPolicy class are subclasses of the PyJWTError type
Are there changes in behavior for the user?
None, multiple inheritance with the old error types has been used to maintain backward compatibility.
Related issue number
Checklist
note: Currently, JWTIdentityPolicy is not documented. Would you like me to add documentation and update the demo?