Adding the option to use a custom user manager to retrieve the user f… #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adding the option to use a custom user manager to retrieve the user from cognito without having to create a custom user model
To use that feature, all you have to do is to configure the variable
COGNITO_USER_MANAGER=cognito_users.models.CognitoManager
Then you can define you own manager:
class CognitoManager(BaseUserManager):
def get_or_create_for_cognito(self, jwt_payload):
username = jwt_payload['cognito:username']
email = jwt_payload['email']
groups = jwt_payload['cognito:groups']
try:
user = get_user_model().objects.get(username=username)
except:
password = get_user_model().objects.make_random_password()
user = get_user_model().objects.create_user(username, email, password)
if 'superusers' in groups:
user.is_superuser = True
user.is_active = True
user.is_staff = True
user.save()
return user
In that way you don't need to customize your COGNITO_USER_MODEL which could be hard on an already running project.
Please, tell me if you would be interested in accepting a feature like that. If you are interested I can add documentation for it