用jwt撤消令牌未存储在数据库adonisjs5中5
我想用Adonis的JWT toker库来撤消一个令牌,只是我正在使用不存储数据库中的令牌的版本。它要求我在撤销令牌上通过刷新令牌,但是当我这样做时,它告诉我这不是有效的JWT令牌
I want to revoke a token with the jwt-token library from adonis, except that I'm using the version where I don't store the token in the database. It asks me at the revoke of the token to pass the refresh token but when I do it tells me that it is not a valid jwt token
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个漫长的话题:)
您可以阅读为什么您不应该使用JWT以及为什么Adonis在这里不支持它: https://github.com/adonisjs/core/discussions/2039#discussioncomment-201869
,但要保持简短...只是不使用JWT。使用Adonis推荐的内容: https://docs.adonisjs.coms.com/guides/ auth/api-tokens-guard
为什么?因为如果您打算撤销JWT,使用JWT没有意义。撤销JWT令牌的唯一“官方”方法是更改用于生成JWT的应用程序秘密。但是,这样做,您将立即撤销所有JWT令牌。
当您创建它们并创建自定义逻辑时,您可以将JWTs写入数据库/redis,以将其定制为白名单/黑名单,以便您可以控制撤销等等。但是,为什么要完全使用JWT。关键是他们是无国籍的。
This is a long topic :)
You can read why you should not use JWT and why Adonis is not supporting it here: https://github.com/adonisjs/core/discussions/2039#discussioncomment-201869
But to keep it short... Just don't use JWTs at all. Use what adonis is recommending: https://docs.adonisjs.com/guides/auth/api-tokens-guard
Why? Because there is no point in using JWTs if you are planning to revoke them. The only "official" way to revoke a JWT token is by changing your app secret which was used to generate JWT. But, doing this you will revoke ALL JWT tokens at once.
You could write JWTs to database/redis when you create them and create custom logic to whitelist/blacklist them so you can control revoking etc. But then why use JWT at all. The point is for them to be stateless.