如何在注销时销毁 JWT 令牌? [英] How to destroy JWT Tokens on logout?
问题描述
我在 hapijs 中使用 jwt 插件和策略.
I am using jwt plugin and strategy in hapijs.
我可以在登录用户时创建 jwt 令牌,并通过jwt"策略使用相同的令牌验证其他 API.
I am able to create jwt token while login user and authenticate other API using the same token through 'jwt' strategy.
我将 request.state.USER_SESSION
中的令牌设置为 cookie,其中 USER_SESSION
是令牌名称.另外,我没有将这些令牌保存在数据库中.
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.
但是如何在注销时销毁 jwt 令牌?
But how can I destroy jwt token at the time of logout?
请提出一种方法.
推荐答案
JWT 存储在浏览器上,所以在客户端删除 cookie 删除令牌
The JWT is stored on browser, so remove the token deleting the cookie at client side
如果您还需要在过期时间之前使服务器端的令牌失效,例如帐户删除/阻止/暂停、密码更改、权限更改、用户由管理员注销,请查看 使 JSON Web 令牌无效 用于创建黑名单或轮换令牌等一些常用技术
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
这篇关于如何在注销时销毁 JWT 令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!