question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TOKEN_MODEL not compatible with JWT

See original GitHub issue

The TOKEN_MODEL variable was introduced in #189. This is used in utils.login_user and utils.logout_user.

The call tosettings.TOKEN_MODEL.objects.filter(user=request.user).delete() doesn’t work with JWT, as it doesn’t define a model as tokens are stored client side, not in the database: https://github.com/GetBlimp/django-rest-framework-jwt/blob/master/rest_framework_jwt/models.py

(The call to settings.TOKEN_MODEL.objects.get_or_create() doesn’t affect JWT, as it’s never called when using JWT.)

For example, attempts to log out a user generates the following error:

  File "/path/to/djoser/djoser/utils.py", line 23, in logout_user
    settings.TOKEN_MODEL.objects.filter(user=request.user).delete()
AttributeError: type object 'Token' has no attribute 'objects'

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
Emnalyeriarcommented, Aug 17, 2019

I just experienced the same problem when trying to delete currently logged user. Sending DELETE request to /users/me/ produces this error:

File "/usr/local/lib/python3.7/site-packages/djoser/utils.py", line 26, in logout_user
    settings.TOKEN_MODEL.objects.filter(user=request.user).delete()
AttributeError: type object 'Token' has no attribute 'objects'

I solved it by setting the TOKEN_MODEL to None as described here https://djoser.readthedocs.io/en/latest/settings.html#token-model

0reactions
krash84commented, Nov 4, 2018

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Web Token Tutorial using AngularJS & Laravel - Toptal
Token based/JWT authentication is stateless, so there is no need to store user information in the session. This gives us the ability to...
Read more >
'System.IdentityModel.Tokens.Jwt 5.1.4' is not compatible with ...
I spoke too soon, ran the site up in VS, Could not load file or assembly 'Autofac' or one of its dependencies. The...
Read more >
Implement JWT In .NET Core API - C# Corner
In this article, you will learn how to implement JWT Authentication in ... will contain definitions for Authentication and TokenModel Model.
Read more >
RFC 7519: JSON Web Token (JWT)
Unsecured JWT A JWT whose claims are not integrity protected or encrypted. ... "JWT" always be spelled using uppercase characters for compatibility with ......
Read more >
JSON Web Token (JWT) RFC 7519 - IETF Datatracker
Unsecured JWT A JWT whose claims are not integrity protected or encrypted. ... "JWT" always be spelled using uppercase characters for compatibility with ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found