Answer the question
In order to leave comments, you need to log in
How to implement authorization/authentication with access/refresh tokens using JWT?
Please explain the key features of the job.
I understand that an access token is needed to authenticate requests, it lives for 15-30 minutes.
I understand that a refresh token is needed to renew an access token, it lives much longer, for example 30 days.
I don't understand:
1. Let's say we log in, create 2 tokens - access and refresh, the last one is written to a special session table in the database, right? (but it's not entirely clear what we store, only the lifetime comes to mind)
If we write down the signature, we can get it anyway using user data.
Record user agent - what if the user updates the browser?
IP - and if it changes wi-fi or switches to SIM?
2. Where do we write these tokens? Someone says access is written in httpOnly cookie, someone says that we write refresh there.
And we can, for example, write both there? (Example - the user makes a request with an expired access token, we check the refresh, if it passes the check, we issue a new access).
The only thing is that you will have to set the cookie on refresh for the entire application (that is, 2 tokens will go away with each request, but why is still unclear), and not only on /auth , like access (well, or make a separate request /auth/refresh -tokens ).
3. Will both of these tokens be JWTs?
Answer the question
In order to leave comments, you need to log in
3. Will both of these tokens be JWTs?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question