Skip to content
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

Add JWT Token Support for Single Page Applications through Django Rest Framework #58

Merged
merged 5 commits into from
Oct 9, 2018

Conversation

mahaffey
Copy link
Contributor

"Closes" Issue #56

I also added the previously asked for get_user_model definition of a User in views.py.

Updated README to reflect new possible settings that I created.

Added two dependencies to this module in setup.py (djangorestframwork-jwt and django-rest-auth).

  • Is there a way to have conditional dependencies to keep this more lightweight for the users who do not have a need for DRF?

My implementation adds a few lines of code before the normal login sequence in views.py.

Instead of immediate redirection to the defined DEFAULT_NEXT_URL, it first checks to see if the user has enabled USE_JWT. If this is set to True, my block of code is then executed.

  1. We first create the JWT from the target_user using jwt_encode
  2. We then check to see if the user has implemented the FRONTEND_URL, if not we fall back to the default, which is DEFAULT_NEXT_URL
  3. We now create the query string consisting of the user id (uid) and JWT (token).
  1. We then redirect to the frontend_url with the query params appended to the string
  2. The client user can now use this token and uid to send with every fetch request, thus enabling SSO/SAML for single page applications

Any feedback would be great! Thanks

@ayr-ton ayr-ton merged commit 451d2bd into fangli:master Oct 9, 2018
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