Token Types & Intended Consumers

Every token in the OAuth / OIDC ecosystem is minted for a specific consumer. Routing a token to the wrong consumer creates severe security vulnerabilities:

graph TD
    subgraph AuthServer["🔑 Authorization Server (IdP)"]
        TokenGen["Issue Token Pair"]
    end

    subgraph ClientApp["💻 Client Application (Relying Party)"]
        IDT["👤 Consumes ID Token
(Reads user profile, sub, email)"] RT["🔄 Stores Refresh Token
(HTTP-only cookie / Secure vault)"] AT_Send["📤 Forwards Access Token"] end subgraph APIGateway["🛡️ API Gateway / Resource Server"] JWKS["Verifies RS256 with JWKS"] RS["🗄️ Consumes Access Token
(Evaluates scopes, roles & RBAC)"] end TokenGen -->|"ID Token (Signed JWT)"| IDT TokenGen -->|"Refresh Token"| RT TokenGen -->|"Access Token (Bearer)"| AT_Send AT_Send -->|"Authorization: Bearer <Access Token>"| JWKS JWKS --> RS RT -.->|"POST /token (grant_type=refresh_token)"| TokenGen
Token TypeIntended ConsumerFormatSecurity Invariant & Lifetime
Access Token Resource Server (API) JWT or Opaque Short-lived (15–60 min). Presented in Authorization: Bearer header. Never inspect inside client apps.
ID Token Client Application Signed JWT Short-lived (5–10 min). Proves user authentication. Never send to backend APIs as Bearer tokens!
Refresh Token Authorization Server Opaque string Long-lived (days/weeks). Used exclusively to fetch fresh access tokens. Stored in HTTP-only cookies or secret vaults.

The Evolution of Tokens: Opaque to JWE

How token standards evolved across the internet:

  • Opaque Random Strings (Pre-2012): Tokens were completely opaque random strings (e.g. SlAV32hkKG). Every API call required the Resource Server to make a synchronous back-channel database lookup or introspection call to the Authorization Server to check validity and user identity.
  • JSON Web Tokens (RFC 7519, 2015): Encoded self-contained identity and access claims into structured JSON. Allows APIs to validate expiration (exp) and scopes locally without database round-trips.
  • JSON Web Signature (JWS - RFC 7515): Added cryptographic signatures (RS256, ES256) to ensure the token payload cannot be forged or tampered with.
  • JSON Web Encryption (JWE - RFC 7516): Encrypts the payload for end-to-end confidentiality when passing sensitive PII across untrusted intermediaries.

Bearer Token Masquerade Risk & Mitigation

⚠️ The Bearer Token Security Invariant:

Access tokens are standard Bearer tokens: Whoever "bears" the token can access the authorized resource without secondary proof of identity. If an attacker steals your access token from browser storage or an insecure log file, they can immediately masquerade as you until the token expires.

Required Mitigations:

  • Enforce short token lifetimes (15 to 60 minutes max).
  • Always transmit over TLS 1.3 / HTTPS.
  • Store tokens in Secure, HttpOnly, SameSite=Strict cookies rather than localStorage.
  • Implement Mutual TLS (mTLS - RFC 8705) or DPoP (Demonstrating Proof of Possession - RFC 9449) for high-security zero trust environments.

Scope vs Claim vs Response Type: The 3 Pillars

1. Scope

The Request (Authorization)

Permissions requested by the Client during the authorization request (e.g. read:reports, openid).

2. Claim

The Assertion (Identity & Context)

Key-value attribute packed inside a signed JWT payload (e.g. "sub": "usr_123", "roles": ["Admin"]).

3. Response Type

The Protocol Instruction

Tells the IdP what token artifacts to return in the front-channel redirect (e.g. code, id_token).

JWT Anatomy & Tamper-Proofing (RFC 7519)

A JSON Web Token consists of three base64url-encoded strings separated by periods: header.payload.signature

HEADER: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleV8yMDI2XzAxIn0
PAYLOAD: eyJpc3MiOiJodHRwczovL2F1dGhtYXRyaXgubG9jYWwiLCJzdWIiOiJ1c3JfYWxpY2VfMTIzIiwicm9sZXMiOlsiQWRtaW4iXX0
SIGNATURE: Td4k7wN5rXyZ_8Pq9LmVoA...
// 1. HEADER (Specifies Algorithm and Key ID)
{
  "alg": "RS256",
  "typ": "JWT",
  "kid": "key_2026_01"
}

// 2. PAYLOAD (Identity and Access Claims)
{
  "iss": "https://authmatrix.local",
  "sub": "usr_alice_123",
  "aud": "https://api.authmatrix.local",
  "exp": 1755003600,
  "iat": 1755000000,
  "roles": ["Admin"],
  "permissions": ["read:reports", "write:users", "delete:audit"]
}

// 3. SIGNATURE (Asymmetric RSA SHA-256)
RS256(Base64URL(Header) + "." + Base64URL(Payload), PrivateKey)

Access Token Payload Anatomy (Okta & Enterprise Standard)

While OAuth 2.0 does not dictate access token formats, modern enterprise providers (Okta, Entra ID, Auth0) issue signed JWT access tokens packed with authorization metadata:

// Decoded Enterprise Access Token (JWT Payload)
{
  "ver": 1,
  "jti": "AT.upPJqU-Ism6Fwt5Fpl8AhNAdoUeuMsEgJ_VxJ3WJ1hk",
  "iss": "https://authmatrix.local/oauth2/default",
  "aud": "https://api.authmatrix.local",
  "sub": "alice@authmatrix.local",
  "uid": "00u2yulup4eWbOttd1t7",
  "iat": 1755000000,
  "exp": 1755003600,
  "cid": "0oa2yrbf35Vcbom491t7",
  "scp": ["openid", "profile", "email", "read:reports", "write:users"],
  "roles": ["Admin", "SecurityEngineer"]
}
Claim KeyPurposeSecurity Function
scpArray of approved scope stringsEvaluated by API Gateway / backend route middleware for Least Privilege RBAC.
uid / subUser Unique IdentifierIdentifies user context for DB audits and row-level multi-tenancy.
cid / client_idApplication IdentifierIdentifies calling application (Client) for throttling and rate limiting.
jtiJWT IDUnique random token GUID; cached by APIs to detect and reject token replay.

Standard & Custom JWT Claims

1. Standard JWT Claims (RFC 7519 Section 4.1)

ClaimNameVerification Rule
issIssuerMust match the exact URL of the Authorization Server.
subSubjectUnique permanent identifier of the user/entity.
audAudienceMust match the API identifier / Client ID. Rejects misrouted tokens.
expExpirationUnix timestamp. Reject if now() > exp.
nbfNot BeforeUnix timestamp. Reject if now() < nbf.
iatIssued AtUnix timestamp indicating token creation time.
jtiJWT IDUnique token GUID used to prevent replay attacks.

RS256 vs HS256 Cryptography

DimensionHS256 (Symmetric)RS256 (Asymmetric)
Key MechanismSingle Shared Secret KeyPrivate Key (Signs) + Public Key (Verifies)
Key Distribution RiskHigh Risk: Every API service must store the shared secret. If one API is breached, the attacker can mint tokens for all services.Zero Secret Leakage: Only the IdP holds the private key. APIs only download public keys.
Enterprise StandardInternal legacy services onlyIndustry Gold Standard for all microservices & cloud architectures.

Dynamic JWKS Key Verification (RFC 7517)

APIs verify incoming tokens without calling the Authorization Server on every request. Instead, they dynamically download public keys from /.well-known/jwks.json:

GET /.well-known/jwks.json HTTP/1.1
Host: accounts.example.com

// Response
{
  "keys": [
    {
      "kty": "RSA",
      "use": "sig",
      "alg": "RS256",
      "kid": "key_2026_01",
      "n": "u1WguZo5WOk5Y...",
      "e": "AQAB"
    }
  ]
}

Key Rotation: When an IdP rotates signing keys, it publishes the new key in the JWKS array. The API matches the JWT header's kid (Key ID) to the JWKS key without downtime.

The Four OAuth Endpoints

1. Token Introspection (RFC 7662)

Allows Resource Servers to validate opaque tokens or check real-time revocation status:

POST /introspect HTTP/1.1
Host: authorization-server.example.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=

token=2YotnFZFEjr1zCsicMWpAA

// Response
{
  "active": true,
  "scope": "read:reports write:users",
  "client_id": "client_app_123",
  "sub": "usr_alice_123",
  "exp": 1755003600
}

2. Token Revocation (RFC 7009)

Explicitly invalidates an active token upon user logout:

POST /revoke HTTP/1.1
Host: authorization-server.example.com
Content-Type: application/x-www-form-urlencoded

token=8xLOxBtZp8&token_type_hint=refresh_token

Web Access Management (WAM) Policies

Modern Zero Trust policy engines evaluate token claims and environmental signals in real time before granting access to sensitive business operations:

🛡️ WAM Real-Time Policy Evaluation Matrix
  • User Identity Context: sub, roles, verified email domain.
  • Resource Context: Requested endpoint (e.g. DELETE /api/protected/audit) and required permission (delete:audit).
  • Environmental Risk Signals: IP Geolocation anomaly, corporate managed device status, and MFA assurance level (acr / amr).