jpadilla / django-rest-framework-jwt

JSON Web Token Authentication support for Django REST Framework
http://jpadilla.github.io/django-rest-framework-jwt/
MIT License
3.19k stars 648 forks source link

Cookie not removed in request when response is 401 #493

Open pedroflying opened 4 years ago

pedroflying commented 4 years ago

I'm using JWT in a httpOnly cookie and allowing multiple logins on the system. If I have 2 sessions opened with the same user (different JWT tokens) and if one of them logs out I reset all JWT tokens by changing the user's UUID. I also delete that session's cookie by means of:

        response = HttpResponse()
        response.delete_cookie("cookie.jwt",path="/")

This logs out both browser sessions and that's OK, but the browser session in which I DID NOT explicitly log out keeps an invalid cookie in the browser and I can't get rid of it via javascript because its httpOnly (I want it to stay that way). All further requests to the server return as a 401 and I can't seem to change the response to add a "delete_cookie".

Two questions:

  1. Why not always delete the cookie JWT_AUTH_COOKIE from the response if an exception is raised by JWT?

  2. How can I work around this issue?

Thanks!