
Once the app receives the token expired response, it sends the expired access token and the refresh token to obtain a new access token and refresh token. Once the access token expires, the server will send a token expired response. The app stores the refresh token safely.Įvery time the app sends a request to the server it sends the access token in the Authorization header and the server can identify the app using it. With refresh token-based flow, the authentication server issues a one-time use refresh token along with the access token. The idea of refresh tokens is that we can make the access token short-lived so that, even if it is compromised, the attacker gets access only for a shorter period.

So, why do we need both access tokens and refresh tokens? Why don’t we just set a long expiration date, like a month or a year for the access tokens? Because, if we do that and someone manages to get hold of our access token they can use it for a long period, even if we change our password! Now, let’s discuss why we actually need refresh tokens.

Steps 3 through 7 keep on repeating until the refresh token expires.The authentication component issues a new access token and refresh token.Once the access token expires, the client requests a new access token by providing the refresh token.After that, the client requests the resource endpoints for a protected resource by providing the access token.Then, the authentication component issues the access token and the refresh token.Now, we are going to introduce the refresh token to our authentication workflow: The lifetime of a refresh token is usually set much longer compared to the lifetime of an access token. When access tokens expire, we can use refresh tokens to get a new access token from the authentication component. Refresh tokens are credentials that can be used to acquire new access tokens. Refresh token-based authentication workflow

#REFRESH OPTION ON DB SOLO CODE#
To download the source code for this article, you can visit our GitHub repository.
