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

Adding request to user method #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ you can use the ``COGNITO_USER_MODEL`` setting.
.. code-block:: python

COGNITO_USER_MODEL = "myproject.AppUser"

(Optional) If you want to send the request object to the custom user model then set the ``COGNITO_USER_MODEL_ADD_REQUEST_OBJ`` to true.

.. code-block:: python

COGNITO_USER_MODEL_ADD_REQUEST_OBJ = True

6 changes: 5 additions & 1 deletion src/django_cognito_jwt/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ def authenticate(self, request):
except TokenError:
raise exceptions.AuthenticationFailed()

add_request = getattr(settings, "COGNITO_USER_MODEL_ADD_REQUEST_OBJ", False)
USER_MODEL = self.get_user_model()
user = USER_MODEL.objects.get_or_create_for_cognito(jwt_payload)
if add_request:
user = USER_MODEL.objects.get_or_create_for_cognito(jwt_payload, request)
else:
user = USER_MODEL.objects.get_or_create_for_cognito(jwt_payload)
return (user, jwt_token)

def get_user_model(self):
Expand Down