There are several reasons to invalidate the JWT token before it expires: the account has been deleted / locked / suspended, the password has been changed, access rights have been changed, the user has logged out of the system as an administrator. So, your question on the topic
There are several methods of application or combination, depending on your use.
1) Remove the client token from the local storage
2) Blacklist of tokens: Save tokens that were between the output and the expiration time, expired and check it in each request. Use a unique identifier jti or specify the last login date and have written out in iat to remove old tokens
Server storage required. If you do not expect too many tokens to be canceled, you can also use the blacklist in memory. You only need to set the record after updating the critical data for the user and currentTime - maxExpiryTime < lastLoginDate (iat)β A record can be discarded if currentTime - maxExpiryTime > lastModified (no more tokens have been specified). In this case, it is not necessary to store the entire token. Just sub , iat and maybe iat
3) The expiration time is short and rotate them. Issue a new access token every few requests. Use refresh tokens so that your application can receive new access tokens without requiring re-authentication and merging with sliding-sessions
Slide sessions are sessions that expire after a period of inactivity. When the user performs an action, a new access token is issued. If the user uses an expired token, the session is considered inactive and a new access token is required. This new token can be obtained using an update token or by requiring credentials.
Other common methods
Allow changing the unique user ID if the account is compromised with a new username and password.
To invalidate tokens when a user changes his password, sign a token with a hash of your password. If the password is changed, all previous tokens are not automatically verified. Extend this mechanism with another sign of interest. The disadvantage is that it requires access to the database
Change signature algorithm to revoke all current tokens in major security issues
Take a look at Invalid JSON Web Tokens
pedrofb
source share