jazzband / django-rest-knox

Authentication Module for django rest auth
MIT License
1.18k stars 213 forks source link

get_or_create returns an AuthToken with token_key, digest, salt = '' when creating the first instance of AuthToken. #195

Open SagarKishore-PFM opened 5 years ago

SagarKishore-PFM commented 5 years ago

Steps to reproduce: (in django shell)

user = YourCustomUser.objects.get(username='your_username') AuthToken.objects.all().delete() token, created = AuthToken.objects.get_or_create(user=user) token.token_key

Here the token will have empty strings for token_key, digest and salt fields when the AuthToken is created for that specific user for the first time. When you run the get_or_create command again, it returns the created Token without issues.

Of course, get_or_create throws error when multiple tokens exist for the User. Which is expected behaviour.

Also, in the admin interface, I cannot delete this bugged out token. Although I can use token.delete() in my Django shell.

Screenshot 2019-10-22 at 12 51 40 PM