Refreshing Tokens
Since JWTs have a strict exp
Expiration Time, a long session might result in multiple logouts and 401 Authentication
errors. To avoid such bahvior, refresh tokens are used to enable the generation of additional access token without the need to log in again.
Implicit refresh with Cookies
WIP
This section is work in progress
Explicit refresh
When your application cannot use implicit refresh because cookies are not an option (mobile application, SDKs, APIs,...), you might need to declare explicitly the refresh logic on you application.
On this example, the /refresh
route will only look for a valid refresh token in request. Once verified, it generates a new access token to be used to extend the session.
This example is a very basic implementation of an explicit refresh mechanism. On a production case you might want to retrieve the current access token to revoke it. Hence avoiding to generate infinite valid access token.
As you can see on the last step, refreshing mechanism allow to obtain new tokens without the need to authenticate again.