Verified by Garnet Grid

Authentication Architecture Patterns

Design enterprise authentication. Covers OAuth 2.0, OIDC, JWTs, session management, passwordless auth, SSO, and choosing between authentication patterns for different application types.

Authentication is the front door of every application. Get it wrong and nothing else matters — your database encryption, network segmentation, and monitoring are all bypassed. This guide covers practical authentication architecture for modern applications, not the theoretical RFC specs.


Auth Pattern Decision Tree

What type of application?
├── Server-rendered web app
│   └── Session-based auth (cookies)
│       Server stores session, cookie contains session ID

├── Single-page app (SPA)
│   └── OAuth 2.0 + PKCE
│       Authorization code flow with PKCE extension
│       Tokens stored in memory (not localStorage)

├── Mobile app
│   └── OAuth 2.0 + PKCE
│       Authorization code flow with PKCE
│       Tokens in secure enclave/keychain

├── API (machine-to-machine)
│   └── OAuth 2.0 Client Credentials
│       Service-to-service with client ID + secret

└── Microservices (internal)
    └── JWT propagation + mTLS
        Gateway validates, services trust JWT + mTLS

JWT Architecture

┌──────────┐       ┌──────────────┐       ┌──────────┐
│  Client  │──────▶│  Auth Server │──────▶│ Resource │
│          │       │  (issues JWT)│       │  Server  │
│          │       └──────────────┘       │(validates│
│          │              │                │  JWT)    │
│          │◀─── JWT ─────┘                │          │
│          │──── JWT in Authorization ────▶│          │
└──────────┘       header                 └──────────┘

JWT Best Practices

PracticeImplementation
Short expiryAccess token: 15 min, Refresh token: 7 days
Audience claimaud: "api.example.com" — reject tokens for other APIs
Issuer validationVerify iss claim matches your auth server
Algorithm pinningAccept only RS256/ES256, reject none and HS256 from external
Key rotationJWKS endpoint with key rotation every 90 days
Token bindingBind token to client fingerprint where possible

Session vs JWT

FactorSessions (Cookies)JWTs (Tokens)
StorageServer-side (Redis/DB)Client-side (stateless)
RevocationInstant (delete session)Hard (need blocklist or short TTL)
ScalabilityNeeds shared session storeStateless, any server validates
CSRF riskYes (need CSRF tokens)No (not auto-sent by browser)
XSS riskLower (httpOnly cookie)Higher (if stored in localStorage)
Best forServer-rendered appsSPAs, mobile, microservices

Passwordless Authentication

MethodSecurityUXImplementation
Magic links (email)MediumGoodEmail with one-time link
Passkeys (WebAuthn)HighExcellentBiometric/device-bound credential
SMS OTPLow (SIM swap risk)FairAvoid for sensitive apps
Authenticator appHighGoodTOTP as second factor
Hardware key (FIDO2)HighestFairUSB/NFC security key

Anti-Patterns

Anti-PatternProblemFix
JWT in localStorageXSS can steal tokensMemory storage + refresh via httpOnly cookie
Long-lived JWTs (24h+)Stolen token valid for too long15-min access token + refresh token rotation
No token revocation mechanismCan’t invalidate compromised tokensToken blocklist in Redis, or short TTL
Rolling your own authInevitable security vulnerabilitiesUse established providers (Auth0, Clerk, Supabase Auth)
Password-only authPhishing, credential stuffingMFA mandatory, consider passkeys
Same secret for all environmentsDev compromise = prod compromiseUnique secrets per environment

Checklist

  • Auth pattern selected based on application type
  • OAuth 2.0 / OIDC implemented (not custom auth)
  • JWT: short-lived (15 min), with refresh token rotation
  • Token storage: secure (not localStorage for SPAs)
  • MFA: mandatory for privileged accounts
  • Session management: secure cookies, proper expiry
  • CSRF protection for cookie-based auth
  • Brute force protection: rate limiting on login
  • Password policy: length over complexity, breach checking
  • Key rotation: JWKS key rotation every 90 days

:::note[Source] This guide is derived from operational intelligence at Garnet Grid Consulting. For authentication architecture consulting, visit garnetgrid.com. :::

Jakub Dimitri Rezayev
Jakub Dimitri Rezayev
Founder & Chief Architect • Garnet Grid Consulting

Jakub holds an M.S. in Customer Intelligence & Analytics and a B.S. in Finance & Computer Science from Pace University. With deep expertise spanning D365 F&O, Azure, Power BI, and AI/ML systems, he architects enterprise solutions that bridge legacy systems and modern technology — and has led multi-million dollar ERP implementations for Fortune 500 supply chains.

View Full Profile →