Mechanism: Refresh Token Rotation (RTR). When a refresh token is used, the old one is invalidated, and a new access + refresh token pair is issued.
Replay Detection: If a rotated token is used again, it implies theft -> chain revocation.
Device Trust:
Why? Phishing, stolen credentials on unmanaged devices.
Mechanism: Device Fingerprinting vs. MDM (Mobile Device Management) integration vs. Platform Authenticators (TPM).
Implementation: During auth, check device posture (is disk encrypted? is OS patched?). This usually requires an agent or a specific protocol like Device Authorization Grant (RFC 8628) or just checking claims from an IdP integrated with an MDM. Let's go with a "Zero Trust" approach: Check during the token issuance or API call.
OIDC Migration: Don't just say "use OIDC." Mention specific claims (sub, email, groups) and UserInfo endpoint.
Token Rotation: Explain the "Refresh Token Family" concept.
Device Trust: This is the hardest part. How do we actually do it?
Option A: Client-side cert (painful).
Option B: Corporate device management (Intune/Jamf) sending telemetry to the IdP (Okta/Auth0/Entra).
Option C: Browser isolation (too complex).
Selection: Focus on integration with an IdP that supports Device Trust (like Okta/Entra ID) and passing the trust signal as a claim in the ID Token. Also, mention Sender Constrained Tokens (DPoP or MTLS) to physically bind the token to the device's key store.
Device Trust: "Compliance check" before issuing token. Use "Sender Constrained Tokens" (HTTP Message Signatures or DPoP) to prevent token theft.
7. Review against the prompt:
Architect: Yes, providing a structural design.
Modernization: Yes, moving away from legacy.
Migrating to OIDC: Covered.
Token Rotation: Covered.
Device Trust: Covered.
Self-Correction during drafting: I initially thought about just "checking" the device. But real device trust implies binding. If I steal a token from a trusted device and move it to an untrusted device, it shouldn't work. Therefore, DPoP (Demonstrating Proof-of-Possession) or MTLS is crucial here. I must emphasize binding tokens to the specific device key pair.
Final Polish: Use professional formatting, bold key terms, and create a logical flow from high-level design to implementation specifics. Add a section on the "Migration Path" because users rarely start from scratch.
(Self-Correction on Migration): The user might be moving from SAML. OIDC is simpler for SP-initiated flows. If they are moving from custom SQL Auth, the migration is about importing hashes or forcing password resets. I will assume a generic legacy state (Custom Auth or SAML) and focus on the target architecture.
Let's organize the Device Trust section carefully. It involves two steps:
Posture Assessment: Is the device healthy? (Is it managed? Encrypted?)
Token Binding: Is the token tied to the device? (DPoP).
Let's write the response.
This architecture outlines a modernization strategy from a legacy authentication system (likely session-based or proprietary) to a standards-based Zero Trust architecture using OpenID Connect (OIDC), Rotated Refresh Tokens, and Device Trust.
1. High-Level Architecture Shift
We will move from a monolithic authentication model to a federated identity model.
Current State (Legacy): Direct credential validation (SQL lookup), long-lived sessions, opaque cookies, no device context.
Target State (Modern): Centralized Identity Provider (IdP), stateless JWTs, short-lived access, ephemeral refresh tokens, and device-bound credentials.
The Core Components
The Identity Provider (IdP): The source of truth (e.g., Okta, Auth0, Entra ID, or Keycloak).
The Client Application (RP): Your frontend (SPA, Mobile, or Web App).
The Resource Server (API): Your backend services.
Device Trust Service: A mechanism to verify and score the device requesting access.
2. Pillar 1: OpenID Connect (OIDC) Implementation
We will implement the Authorization Code Flow with PKCE (Proof Key for Code Exchange). This is the industry standard for all modern applications, including server-side web apps and SPAs.
The Flow
Initiation: The user clicks "Login." The app generates a code_verifier and code_challenge.
Redirection: The app redirects to the IdP login page.
Authentication: User authenticates (MFA required).
Code Return: IdP redirects back with an authorization_code.
Token Exchange: The app sends the code + code_verifier to the IdP token endpoint.
To mitigate token theft, we will treat tokens as ephemeral assets.
Strategy: Refresh Token Rotation (RTR)
Instead of a static Refresh Token that lives forever (or for months), we implement Rotation. Every time a Refresh Token is used to get a new Access Token, the IdP issues a new Refresh Token and invalidates the old one.
Refresh Token Lifespan: Longer (e.g., 24 hours to 7 days), but absolute lifetime requires re-authentication.
Automatic Reuse Detection:
If an attacker steals a Refresh Token (Token A) and uses it, the IdP returns a new pair (Access B, Refresh B).
The legitimate user tries to use the now-stale (Token A).
The IdP detects that Token A was already rotated.
Security Action: The IdP immediately revokes the entire session (including Refresh B), forcing the user to re-authenticate. This alerts the system to a potential breach.
Implementation Detail
Storage: Web Apps must use HttpOnly, Secure, SameSite=Strict cookies for Refresh Tokens. LocalStorage is strictly prohibited.
Reference Tokens: For high-security APIs, Access Tokens may be "Reference Tokens" (random strings) rather than JWTs, requiring the API to introspect them at the IdP for every request (or via a cached introspection).
4. Pillar 3: Device Trust (Zero Trust Signal)
Authentication is no longer just "Who are you?" (Identity), but also "What are you using?" (Device).
The Device Trust Workflow
This integrates into the OIDC flow as an Step-up Authentication or an inline hook.
A. Device Registration (The "Trust" Anchor)
When a user logs in for the first time on a new device:
Device trust is not static. If the device OS falls out of compliance (e.g., outdated security patch), the IdP must revoke the Refresh Token immediately during the next rotation attempt.
5. The Integrated Sequence
Here is how these three pillars work together in a single login transaction.
User initiates login.
Client collects device signals (User Agent, MDM status) and redirects to IdP.
IdP challenges for credentials + MFA.
IdP checks Device Trust Service:
Is device managed? Yes.
Is OS compliant? Yes.
IdP issues tokens (OIDC):
ID Token: Includes device_id claim.
Access Token: Includes scp (permissions).
Refresh Token: Configured for Rotation.
User Access: User accesses API. Access Token is valid for 15 mins.
Rotation: After 15 mins, Client sends Refresh Token (A) to IdP.
IdP Response: IdP sends Access Token (New) and Refresh Token (B). Token (A) is burned.
Security Event: If the user later tries to use Token (A) (implying theft), the IdP revokes the session and alerts security.
6. Migration Strategy
Migrating users without downtime requires a phased approach.
Phase 1: Parallel Run (The "Strangler Fig" Pattern)
Deploy the new OIDC IdP.
Keep the legacy SQL auth system.
When a user logs in via the legacy system, trigger a backend process to create a corresponding user in the new IdP (Migration on Login).
Force a password reset or verify hashes (if using Bcrypt/Argon2, you can migrate hashes depending on the IdP support).
Phase 2: Feature Flag Cutover
Introduce a feature flag in the application.
For a small % of users, redirect the login button to the OIDC flow instead of the legacy login form.
Monitor errors and user friction.
Phase 3: Enforcement
Mandate MFA enrollment.
Cut off legacy access to APIs (force JWT validation middleware).