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