Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 7 commits into from
Feb 21, 2017
Merged

Unify JWT based helpers #306

merged 7 commits into from
Feb 21, 2017

Conversation

codejudas
Copy link
Contributor

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.

def payload(self):
if self.__decoded_payload:
return self.__decoded_payload
else:
Copy link
Contributor

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

Copy link
Contributor

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.

"""

if not self.secret_key:
raise ValueError('Jwt does not have a signing key configured.')
Copy link
Contributor

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.

@@ -0,0 +1,25 @@


Copy link
Contributor

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.

@dougblack
Copy link
Contributor

+1 on content, just called out a few style things.

@codejudas codejudas merged commit b5f007d into next-gen Feb 21, 2017
@ilanbiala ilanbiala deleted the next-gen-jwt branch July 11, 2017 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants