SuperAPI AI Directory

oauth2-oidc-and-token-lifecycle

Security & auditing

View repository

Updated 10-16 06:28

About this skill

OAuth2 OIDC And Token Lifecycle

Use When

  • Building SSO or federated login
  • Implementing delegated API access with standards-based tokens

Workflow

  1. Select grant types per client (PKCE for public clients, client credentials for machine clients).
  2. Define token claims, scopes, and audience boundaries.
  3. Implement secure token validation on backend services.
  4. Design refresh, rotation, revocation, and session expiry behavior.
  5. Add observability for auth failures and suspicious token usage.

Provider And Flow Guidance

  • Prefer authorization code with PKCE for browser and mobile clients.
  • Keep access tokens short-lived; use refresh tokens with rotation for longer sessions.
  • Validate tokens at every trust boundary; never trust client-side checks alone.
  • Map scopes to business actions, not broad technical group names.

Required Checks

  • Token signature, issuer, audience, and expiry are validated server-side
  • Scope and claim checks are enforced per protected endpoint
  • Token refresh and revocation paths are deterministic

Decision Framework

  • Prefer authorization code with PKCE for browser and mobile clients.
  • Keep access tokens short-lived; use refresh tokens with rotation for longer sessions.
  • Validate tokens at every trust boundary; never trust client-side checks alone.
  • Map scopes to business actions, not broad technical group names.

Common Rationalizations And Rebuttals

  • "Client already checked auth." -> Client checks are bypassable; enforce authorization server-side.
  • "Long-lived access tokens reduce complexity." -> They increase blast radius after compromise.
  • "Any valid token should work across APIs." -> Enforce audience restrictions to avoid token confusion.

Evidence Pack

  • Flow diagram covering login, refresh, logout, and revocation
  • Negative test evidence for invalid issuer, expired token, wrong audience, and missing scope
  • Key rotation or JWKS failure handling notes
  • Security alert dashboard for auth anomalies

Exit Criteria

  • Identity flows are standards-compliant and secure
  • Token misuse and failure modes are detectable and recoverable