处理 JWT 和刷新令牌流

Handling JWT and Refresh token flow

我正在构建一个内置于 React 中的前端,它可以访问我也在构建的多个微服务 API。对于身份验证,我构建了一个 jwt 登录系统,但想知道处理刷新令牌的过程是什么。

  1. jwt 中的刷新令牌是否带有用户信息,还是在其自己的令牌中使用不同的加密以提供额外保护?

  2. 如果它是在它自己的令牌中,如果 jwt 无效并且需要刷新,其他微服务应该如何响应 react 应用程序。是否使用了通用的 http 状态代码?

  3. 我读到刷新令牌应该比您的 jwt 更安全,因为它可用于发布 jwt 并且具有更长的活动时间。是否有任何额外的加密安全性可以在服务器端或客户端完成但尚未为 jwts 完成?

  4. 什么时候应该使用新的令牌和时间戳刷新刷新令牌使其失效?

Is the refresh token inside the jwt with the user info or is it in its own token with a different encryption for extra protection?

如果您询问的是 Oauth2 中定义的刷新令牌,则在用户身份验证成功后,授权服务器会返回一个刷新令牌。它只是一个随机字符串。使用刷新令牌,客户端可以获得访问令牌(您的 JWT)

If it is in its own token what should the other micro services respond with to the react app if the jwt is invalid and needs to be refreshed. Is there a common http status code used?

他们必须拒绝请求。使用 401- 未经授权

I have read that a refresh token should be more secure then your jwt cause it can be used to issue jwts and will have a longer active time. Is there any extra security past encryption that can be done server side or client side that isnt already done for jwts?

使用 https 获取刷新令牌。附加加密不会提高安全级别,因为拥有令牌就是身份验证证明。但是你需要保证它的安全

When should you refresh the refresh token with a new token and timestamp that it becomes invalid?

取决于系统。 Oauth2 没有指定它。通常寿命很长,但在某些情况下,我看到建议在每次使用后更新它。