Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to generate token for inactive user #607

Open
vitalii-bulyzhyn opened this issue Sep 3, 2022 · 2 comments · May be fixed by #834
Open

Allow to generate token for inactive user #607

vitalii-bulyzhyn opened this issue Sep 3, 2022 · 2 comments · May be fixed by #834

Comments

@vitalii-bulyzhyn
Copy link

I have next auth logic in my service:

  1. User creates account (by default is_active = False). That should automatically log him in and and send verification email
  2. If user is not verified - functionality will be blocked for him
  3. 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?

@vitalii-bulyzhyn
Copy link
Author

vitalii-bulyzhyn commented Sep 7, 2022

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

@hvdklauw
Copy link

hvdklauw commented Jan 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants