Hard20 minWeb Fundamentals
UpdatedAug 5, 2026
Edit

OIDC discovery and JWKS

CONCEPTS:OpenID ConnectJWT Security

Question Variations

  • "How does a relying party handle signing-key rotation?"
  • "Why should an application configure an issuer rather than accept one from a request?"
  • "What should happen when a token has an unknown kid?"

Why This Is Asked

OIDC integrations need a secure way to find endpoints and signing keys without hardcoding every value. This question tests trust anchoring, metadata validation, key rotation, caching, and why discovery must not begin from an attacker-controlled issuer string.

Key Concepts

  • Discovery document: Issuer metadata at the well-known OpenID configuration endpoint.
  • JWKS: A published set of public keys used to verify signed tokens.
  • Key IDs: kid selects a candidate key during planned rotation.
  • Trust anchor: The issuer is configured by the application before discovery starts.

Question Variations

  • “How does a relying party handle signing-key rotation?”
  • “Why should an application configure an issuer rather than accept one from a request?”
  • “What should happen when a token has an unknown kid?”

Answers by Technology

+ Add Variant
System DesignImprove this answer ✏️

Expected Answer (OpenID Connect Discovery 1.0)

OIDC discovery begins with an issuer that the application has configured and trusts. The relying party retrieves that issuer’s OpenID Provider metadata from its well-known configuration endpoint, verifies that the returned issuer is exactly the expected issuer, and uses metadata such as authorization_endpoint, token_endpoint, and jwks_uri. It must not start this process from a user-controlled issuer URL, because that would let an attacker choose endpoints and signing keys.

The JWKS endpoint contains public keys used to verify tokens. Each key normally has a kid; the relying party uses it to select a candidate trusted key and caches the set according to HTTP cache controls. During planned rotation, the issuer publishes the new key before signing with it. If a token has an unknown kid, refresh the JWKS once and then reject the token if the key remains unknown—do not accept an arbitrary key embedded in the token or fetch a JWKS from an untrusted URL.

Why It Matters

Discovery and JWKS simplify endpoint and key rotation, but only when the issuer remains the explicit trust anchor. Incorrect key retrieval turns signature verification into verification against attacker-provided keys.

Example Code

interface ProviderMetadata {
  issuer: string;
  jwks_uri: string;
  authorization_endpoint: string;
}

export async function loadProvider(issuer: string): Promise<ProviderMetadata> {
  const response = await fetch(`${issuer}/.well-known/openid-configuration`);
  const metadata = await response.json() as ProviderMetadata;
  if (metadata.issuer !== issuer || !metadata.jwks_uri.startsWith(`${issuer}/`)) {
    throw new Error('Untrusted OIDC metadata');
  }
  return metadata;
}

Common Mistakes

  • Trusting a token’s jku header by default: This lets a token direct the verifier to attacker-controlled keys.
  • Caching JWKS forever: Legitimate key rotation then causes outages or encourages unsafe bypasses.
  • Refreshing keys for every request: This creates avoidable latency and a dependency-amplification problem; follow cache controls and refresh on an unknown key ID.

Follow-up Questions

  • What is the purpose of kid? (Answer: It identifies a key in a set so verifiers can select the proper candidate during rotation.)
  • Why validate the metadata issuer? (Answer: It confirms that the discovered configuration belongs to the configured trust anchor.)

References