The Real Fullstack

The Expired Token

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

Engenheiro8 minSimulador de linha do tempoDesafio de código
oauth2openid-connectangularhttp

Este desafio ainda não foi traduzido para Português (Brasil). Você está lendo a versão em inglês.

Missão:Keep sessions seamless when the token expires mid-burst, while keeping refresh token rotation (and its theft detection) enabled.Contexto · Objetivos de aprendizagem ▾

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”.

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

Objetivos de aprendizagem

  • Explain access/refresh token lifecycles.
  • Understand refresh token rotation and reuse detection.
  • Coordinate concurrent refreshes (single flight) or refresh proactively.
SimulaçãoSimulado

Execute a simulação para ver a saída.

Executar simulação
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)));

Simplificação

Five concurrent requests at the exact moment of expiry; network timing is ignored. Modelo educacional — os números ilustram comportamento, não são benchmarks.

Conceitos

Desafios relacionados

Referências