I want to figure out how to properly implement the update jwt for web - applications.
By googling I found the answer https://stackoverflow.com/questions/26739167/jwt-json-web-token-automatic-prolongation-of-expiration . But as I understand there they offer to store in the token itself the time when the current token needs to be blocked and issued a new one. Those. it turns out that if the token is stolen, then it can be used indefinitely since if there is a token and the update time expires, a new valid token is issued. Or we hammer on a problem of theft of a token, hoping for HTTPS?
Still came across a scheme with jwt and refresh tokens, such as the new jwt can only be obtained if you present a refresh token. In this scheme, I saw the following situation:
- The client makes a request to the server passing already expired jwt
- The server gives 401/403
- To prevent the end user from authenticating again, the client catches this 401/403 error and makes a request for a new jwt presenting a refresh
- The server issues a new jwt (and possibly plus a new refresh token yet) and the client repeats request # 1, but with a valid jwt and everyone is almost happy.
For the end user, such a scheme is likely to look like a long page load.
In summary, how to update jwt correctly so that it is safe and the end user is satisfied?