Comments (5)
I found the solution now. I have to startapp
with customized User
class
import uuid
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin, UserManager, AbstractUser
from django.contrib.auth.validators import UnicodeUsernameValidator
from django.db import models, IntegrityError
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
class CustomizedUserManager(UserManager):
def get_or_create_for_cognito(self, payload):
cognito_id = payload['sub']
try:
return self.get(cognito_id=cognito_id)
except self.model.DoesNotExist:
pass
try:
user = self.create(
cognito_id=cognito_id,
email=payload['email'],
is_active=True)
except IntegrityError:
user = self.get(cognito_id=cognito_id)
return user
class User(AbstractBaseUser, PermissionsMixin):
username_validator = UnicodeUsernameValidator()
username = models.CharField(
_('username'),
max_length=150,
unique=True,
help_text=_('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'),
validators=[username_validator],
error_messages={
'unique': _("A user with that username already exists."),
},
)
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=150, blank=True)
email = models.EmailField(_('email address'), blank=True)
is_staff = models.BooleanField(
_('staff status'),
default=False,
help_text=_('Designates whether the user can log into this admin site.'),
)
is_active = models.BooleanField(
_('active'),
default=True,
help_text=_(
'Designates whether this user should be treated as active. '
'Unselect this instead of deleting accounts.'
),
)
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
EMAIL_FIELD = 'email'
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']
cognito_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
objects = CustomizedUserManager()
And add AUTH_USER_MODEL = 'customized_users.User'
to settings.py
from django-cognito-jwt.
But this error is before migrations. After adding AUTH_USER_MODEL, another error comes.
use , AUTH_USER_MODEL = 'nameOfApp.nameOfModel', should wourk just fine
from django-cognito-jwt.
Do I really need to create a new app with startapp
? I'm trying to get this to work within my existing app. But not having any luck.
from django-cognito-jwt.
But this error is before migrations. After adding AUTH_USER_MODEL, another error comes.
from django-cognito-jwt.
But this error is before migrations. After adding AUTH_USER_MODEL, another error comes.
use , AUTH_USER_MODEL = 'nameOfApp.nameOfModel', should wourk just fine
What if I have multiple class inherited from AbstractUser
?
from django-cognito-jwt.
Related Issues (20)
- Example authentication flow? HOT 5
- AWS Lambda
- ValueError: too many values to unpack (expected 2) After use customized `User` model HOT 1
- Python 3.5 does not support f' format HOT 3
- Unable to accept Cognito Access Tokens HOT 2
- Cognito Audience Optional HOT 1
- `.get_public_key` in TokenValidator return None
- Can i add Multiple Clients/Audience Id in django settings.py HOT 1
- How to use this library with GraphQL?
- USER_MODEL.objects.get_or_create_for_cognito implementation? HOT 8
- LICENSE file should be packaged to the pypi archive
- Using the Django admin interface HOT 2
- WrappedAttributeError at / module 'jwt' has no attribute 'ExpiredSignature' HOT 3
- token_validator giving urllib3 error
- ImportError: cannot import name 'RSAAlgorithm'.
- Replace ugettext and smart_text with proper functions for Django 4 compatibility
- validate token error HOT 1
- Can this package work for EXTERNAL_PROVIDER HOT 1
- Investigate if we can support the new alb auth HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-cognito-jwt.