feat(api-client): extend OAuthProvider with automatic token lifecycle, JWT exp decoding, and rotation #21
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
qa:preview
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
quatrain/core#21
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context & Motivation
Currently,
OAuthProviderin@quatrain/api-client(packages/api-client/src/auth/OAuthProvider.ts) is only a thin wrapper around a callback:As a consequence, applications using
@quatrain/api-client(such as@totalymage/backoffice-ui) are maintaining ad-hoc local legacy wrappers to handle token storage, expiration checking, single-flight refresh calls, and token rotation.To enable applications to adopt
@quatrain/api-clientdirectly without local wrapper boilerplate,@quatrain/api-clientshould provide an autonomous, robust OAuth token lifecycle management strategy.Proposed Features & Requirements
1. Robust JWT Expiration Decoding (
getJwtExpiration)expclaim from the access token JWT (RFC 7519) without heavy external dependencies.exp * 1000) as the primary source of truth for token TTL, avoiding reliance on relative JSON payload fields (expiresInvsexpires_in).2. Autonomous Token Lifecycle Manager in
OAuthProviderProvide a full-featured
OAuthProvider(orManagedOAuthProvider) with:getItem,setItem,removeItem) with built-inLocalStorageAdapterfor browsers andMemoryStorageAdapterfor Node/SSR.refreshTokenon every renewal cycle.onTokenRotated,onSessionExpired(e.g. to redirect to sign-in on invalid refresh token).3.
ApiClientCore ErgonomicsX-Client-ID: backoffice) that merge automatically into all outbound requests.getBlob): Native method to fetch authenticated binary blobs (Response.blob()) for media/image rendering and downloads.4. Quality & Compliance Standards
as any,@ts-ignore, or@ts-nocheck.packages/api-client/src/auth/OAuthProvider.test.tsandApiClient.test.tsvalidating concurrent refresh, expiration calculations, and error handling.