djangorestframework-simplejwt
djangorestframework-simplejwt copied to clipboard
Allow to generate token for inactive user
I have next auth logic in my service:
- User creates account (by default is_active = False). That should automatically log him in and and send verification email
- If user is not verified - functionality will be blocked for him
- After the verification - *is_active = True, so user can do whatever he wants
The problem here is that simplejwt does not support token generation for inactive user
I think this logic is quite common, so maybe it has sense to add to settings something like:
SIMPLE_JWT = {
"ALLOW_INACTIVE": True
}
What do you think?
For those one who's looking for this logic, it's in settings.py need to add next:
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.AllowAllUsersModelBackend']
def user_authentication_rule(user):
return user
SIMPLE_JWT = {
...,
'USER_AUTHENTICATION_RULE': 'django.conf.settings.user_authentication_rule',
}
But I'm just wondering if that should be a default behaviour when the user authentication model is set to AllowAllUsersModelBackend
Mentioned method does not actually work.
The reason is this line: https://github.com/jazzband/djangorestframework-simplejwt/blob/master/rest_framework_simplejwt/authentication.py#L134
But I agree that the authentication backend should handle things like that.