-
Notifications
You must be signed in to change notification settings - Fork 772
Unify JWT based helpers #306
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
Conversation
87d5be0
to
05133ff
Compare
twilio/jwt/__init__.py
Outdated
def payload(self): | ||
if self.__decoded_payload: | ||
return self.__decoded_payload | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think it's usually clearer to write these functions that have two branches where the first is kind of a base case, short-circuity thing like
@property
def payload(self):
if self.__decoded_payload:
return self.__decoded_payload
payload = self._generate_payload().copy()
# ...
return payload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It visually separates the happy and sad paths.
twilio/jwt/__init__.py
Outdated
""" | ||
|
||
if not self.secret_key: | ||
raise ValueError('Jwt does not have a signing key configured.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: JWT
is an abbreviation so it's typically fully-capitalized.
twilio/jwt/compat.py
Outdated
@@ -0,0 +1,25 @@ | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove blank lines at top of file.
+1 on content, just called out a few style things. |
Rewrite JWTs to all be derived from a Jwt base class, move a lot of general jwt logic into base classes. Simplify the code.
Question: I stopped short of having each Jwt subclass deserialize a jwt string into its internal representation, we could (somewhat) easily do that, wondering if its worth it. Would allow a user to deserialize a AccessToken for instance, modify it via the helper functions/have proper validation, and then re-serialize it.