什么是刷新令牌授权程序

发布于 2025-02-13 07:37:30 字数 172 浏览 1 评论 0原文

我目前正在与Expressjs一起从事一个项目。对于用户授权,我使用JWT令牌,但直到现在只有访问令牌,因为我只是不理解它们与真实示例。因此,有人可以向我解释当某人登录他的帐户时,授权是什么。
FE:

  1. 刷新和访问令牌会产生的
  2. 令牌被存储在数据库等

I'm currently working on a project with expressjs. For user authorization I use JWT tokens but until now only access tokens, because I just don't understand them together with a real example. So can somebody explain to me what the steps are the authorization goes through when someone logs into his account.
f.E.:

  1. Refresh and Access Tokens get generated
  2. Token gets stored into database etc.

Thank you in advance and have a great day

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如日中天 2025-02-20 07:37:31
  1. 用户发送带有登录凭据服务器的邮政请求
  2. ,如果成功,则返回JWT(通常在Httponly cookie中)。服务器不将JWT存储在数据库中。 JWT的重点是身份验证状态由其承载者存储。
  3. 对于后续的对受保护端点的请求,客户需要附加JWT。服务器应检查JWT是否过期以及是否已更改。

您可能想考虑的扩展:

  • 如何刷新JWTS:
    可以使用不同的令人耳目一新的模式。为了
    例如,您可以每次检查JWT的到期
    服务器收到请求。如果JWT即将到期,请发行新鲜
    JWT。
  • 如何在客户端维护身份验证状态,而无需每次刷新页面时登录
  • 如何真正记录用户:
    如果将到期设置为30分钟,并且用户在第15分钟标记处注销,那么JWT在技术上仍然可以使用该端点再访问受保护的端点15分钟。
  1. User sends a POST request with login credentials
  2. Server authenticates and if successful, returns a JWT (usually in a httpOnly cookie). Server does not store JWTs in a database. The whole point of JWT is that authentication state is stored by the bearer of it.
  3. For subsequent requests to protected endpoints, client needs to attach JWT. Server should check if JWT is expired and whether it has been altered.

Extensions that you might want to think about:

  • How to refresh JWTs:
    There are different refreshing patterns that can be used. For
    example, you can check the expiry of the JWT every time that your
    server receives a request. If JWT is expiring soon, issue a fresh
    JWT.
  • How to maintain authentication state on client-side without having to log in every time you refresh the page
  • How to really log a user out:
    If you set the expiry as 30 minutes and a user logs out at the 15th minute mark, that JWT can technically still be used to access protected endpoints for another 15 minutes.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文