Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to destroy JWT Tokens on logout?

I am using jwt plugin and strategy in hapijs.

I am able to create jwt token while login user and authenticate other API using the same token through 'jwt' strategy.

I am setting the token in request.state.USER_SESSION as a cookie where USER_SESSION is a token name. Also, I am not saving these token in the database.

But how can I destroy jwt token at the time of logout?

Please suggest a way.

like image 976
Garima Avatar asked Jun 22 '16 06:06

Garima


People also ask

How do you destroy the JWT token on logout in flask?

If you want to invalidate the token you need to blacklist the token in a table & check on views/routes or delete the token from client so that client needs to regenerate the token again.

Is JWT tokens should be invalidated on the server after logout?

A logout (or invalidate) for the Session Store approach would require an update to the KeyValueStore database with the specified token. It seems like such a mechanism would not exist in the token-based approach since the token itself would contain the info that would normally exist in the key-value store.


1 Answers

The JWT is stored on browser, so remove the token deleting the cookie at client side

If you need also to invalidate the token from server side before its expiration time, for example account deleted/blocked/suspended, password changed, permissions changed, user logged out by admin, take a look at Invalidating JSON Web Tokens for some commons techniques like creating a blacklist or rotating tokens

like image 79
pedrofb Avatar answered Oct 21 '22 07:10

pedrofb