Refresh token backend or frontend #2039
Replies: 2 comments 2 replies
-
Short answerRefresh tokens is mainly a concept originated from JWT tokens. AdonisJS doesn't use JWT and it uses database backed tokens, hence there is no need to have refresh tokens at all. Long answerJWT tokens are self contained and never saved to any backend storage. This is how the flow looks like
The entire flow doesn't need any database or any other kind of storage. But this creates a huge security gap, since the backend always accepts the token until it can be verified using the secret key
Because of this, the industry recommends giving smaller expiry to your JWT tokens. It is usually as small as 5mins. Now, if the tokens get leaked, they can be used for next 5mins only. But this hampers the UX of the application, as now the user has to login every 5mins. So industry came up with another idea of refresh tokens. Refresh tokens are saved in the database on the backend and are usually long lived or atleast don't expiry in minutes. Now when the JWT expires, the client can use the refresh token to generate a new JWT token. Also, if the refresh token gets leaked. As the app owner, you just have to delete them from your database and the tokens are now useless.
JWTs are over rated and not required in 99% of the cases. Finally, I recommend reading the following posts and if have some spare time, also watch the video http://cryto.net/~joepie91/blog/2016/06/13/stop-using-jwt-for-sessions/ |
Beta Was this translation helpful? Give feedback.
-
How to make expiry works instead of total 30 mins from login, idle session of 30 mins ? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have been asked to implement refresh token logic, but I am unsure how to begin.
I am using v5, and how it was explained was
I know how to do it in the front end, I used react native in a different project, with axios, and axios has a intercept option that can do this.
My question is, is this best practice, is there something else I should do in the backend?
Just open for suggestions and discussions.
Beta Was this translation helpful? Give feedback.
All reactions