X
X
xenofobius2018-03-06 21:46:58
Django
xenofobius, 2018-03-06 21:46:58

How to use your token instead of sessionid in django?

I use JWT, on the client side in Angular they get a token and write it to cookies, and it works. How to do the same through the login in djangorestframework or through the admin panel? As I suppose it needs to be redefined in the middleware

'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',

However, everything that I found on the internet regarding custom authentication returns the model of the received user according to the received username and password returns the current user, I did not find the method that sets and checks the sessionid, and did not find how I can override it for a token. Actually from the documentation:
class MyBackend:
    def authenticate(self, request, username=None, password=None):
        # Check the username/password and return a user.
        ...

In fact, all I'm trying to implement is adding a token to cookies upon login and forcing a logout if it has expired.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2018-03-07
@ksenofobius

So in the middleware, a user is created in the process_request and there, when it is created, the presence of a session cookie is checked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question