The Real Fullstack

The Expired Token

Refresh token rotation was supposed to make sessions safer. Why does it log users out of the dashboard?

工程师8 分钟时间线模拟器代码挑战
oauth2openid-connectangularhttp

此挑战尚未翻译为简体中文,你正在阅读英文版本。

任务:Keep sessions seamless when the token expires mid-burst, while keeping refresh token rotation (and its theft detection) enabled.背景 · 学习目标 ▾

Quillfin's Angular app uses short-lived access tokens and rotating refresh tokens. The dashboard fires five API calls on load. When the access token has just expired, users are sometimes thrown back to the login page. The auth server's log says “refresh token reuse detected — revoking session”.

任务: Keep sessions seamless when the token expires mid-burst, while keeping refresh token rotation (and its theft detection) enabled.

学习目标

  • Explain access/refresh token lifecycles.
  • Understand refresh token rotation and reuse detection.
  • Coordinate concurrent refreshes (single flight) or refresh proactively.
模拟模拟数据

运行模拟以查看输出。

运行模拟
export const authInterceptor: HttpInterceptorFn = (req, next) =>  next(withToken(req)).pipe(catchError((e) => e.status === 401    // every failing request starts its own refresh with the same refresh token    ? inject(Auth).refresh().pipe(switchMap(() => next(withToken(req))))    : throwError(() => e)));

简化说明

Five concurrent requests at the exact moment of expiry; network timing is ignored. 教学模型——数字用于说明行为,并非基准测试。

概念

相关挑战

参考资料