Files
ArchiTools/src
Claude VM 47ca366984 fix(auth): Authentik access_token refresh flow
Authentik provider pk=6 issues access tokens with 5-minute TTL but
NextAuth's JWT cookie lives 30 days. Without refresh, every api.gis.ac
call after the first 5 minutes returned 401 invalid_token — the exact
failure Marius hit on first Faza E pilot test.

Implementation:
- jwt callback captures account.refresh_token + account.expires_at on
  first sign-in alongside access_token.
- Before each jwt issuance, if access_token is within 30s of expiry
  and a refresh_token exists, POST to {issuer}/token/ with
  grant_type=refresh_token + client_id + client_secret. Update token
  with the new access_token + expiry + (rotated) refresh_token.
- On failure, set token.error="RefreshAccessTokenError" and stop
  trying (avoid hot-loop). Surfaced via session.error so client UI
  can prompt re-login.

AUTHENTIK_SCOPES updated in Infisical to include `offline_access` so
Authentik issues a refresh_token on first sign-in (standard OAuth2).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 22:13:19 +03:00
..