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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]

tests_require = [
'coverage==.4.4.2',
'coverage==4.4.2',
'pytest==3.3.2',
'pytest-cov==2.5.1',
'pytest-django==3.1.2',
Expand Down
17 changes: 15 additions & 2 deletions src/django_cognito_jwt/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from django.utils.translation import ugettext as _
from rest_framework import exceptions
from rest_framework.authentication import BaseAuthentication, get_authorization_header
from django.utils.module_loading import import_string


from django_cognito_jwt.validator import TokenError, TokenValidator

Expand All @@ -28,10 +30,21 @@ def authenticate(self, request):
except TokenError:
raise exceptions.AuthenticationFailed()

USER_MODEL = self.get_user_model()
user = USER_MODEL.objects.get_or_create_for_cognito(jwt_payload)
custom_user_manager = self.get_custom_user_manager()
if custom_user_manager:
user = custom_user_manager.get_or_create_for_cognito(jwt_payload)
else:
USER_MODEL = self.get_user_model()
user = USER_MODEL.objects.get_or_create_for_cognito(jwt_payload)
return (user, jwt_token)

def get_custom_user_manager(self):
result = None
custom_user_manager_path = getattr(settings, "COGNITO_USER_MANAGER", False)
if(custom_user_manager_path):
result = import_string(custom_user_manager_path)()
return result

def get_user_model(self):
user_model = getattr(settings, "COGNITO_USER_MODEL", settings.AUTH_USER_MODEL)
return django_apps.get_model(user_model, require_ready=False)
Expand Down