JWT 和身份验证 safety/patterns

JWT and authentication safety/patterns

我正在使用 JWT 令牌在 javacript 中构建身份验证和授权系统 基本上当我登录时我存储在 httponly cookies:

当 JWT 仍然有效时,受保护页面将对用户有效性进行远程检查(我请求 API 传递用户 ID 和身份验证令牌作为授权载体) 远程检查可能需要一些时间(不到一秒),但每个受保护的页面在检查时都会显示加载微调器;我想知道假设用户已登录 JWT 仍然有效(或者刷新令牌获得新的 JWT)并且包含用户数据的 cookie 存在,这有多安全。不涉及外部请求,除非您需要刷新 JWT

i was wondering how safe is assuming the user is logged in it the JWT is still valid (or the refresh token get a new JWT) and the cookie with the user data is present

JWT 不适合作为管理会话的机制。 JWT 有自己的到期时间,这与用户的会话无关。如果您需要管理用户的会话,只需使用会话机制,并废弃 JWT。