Skip to content
ecdsa.com
jose (JavaScript)JWKS and key discovery

Error message

Expected 200 OK from the JSON Web Key Set HTTP response

jose (JavaScript) — JOSEError from createRemoteJWKSet, code ERR_JOSE_GENERIC

What it means

`createRemoteJWKSet` requested the key set URL and got an HTTP status other than 200. jose fetches the JWKS with redirects disabled (`redirect: "manual"`), so a 301/302 counts as a failure just like a 404 or 401. No key was loaded and no token signature was checked; the URL you configured does not answer with a key set.

Why it happens

How to fix it

  1. 1.

    Read jwks_uri from the discovery document

    OpenID Connect providers publish the exact key set URL as `jwks_uri` in `/.well-known/openid-configuration`. Resolve it once at startup and pass that URL to `createRemoteJWKSet`.

    js
    import { createRemoteJWKSet } from "jose";
    
    // Resolve jwks_uri from the provider's discovery document instead of guessing it.
    const discovery = await fetch("https://login.example.com/.well-known/openid-configuration").then((r) => r.json());
    const jwks = createRemoteJWKSet(new URL(discovery.jwks_uri));
  2. 2.

    Check the status code without following redirects

    curl without `-L` behaves like jose. A 200 with `{"keys":[...]}` is what you need; a 30x tells you the URL to configure instead.

    bash
    # Status line and redirect target, without following redirects (jose does not follow them either)
    curl -sS -o /dev/null -w '%{http_code} %{redirect_url}\n' https://login.example.com/jwks
    curl -s https://login.example.com/.well-known/openid-configuration | jq -r .jwks_uri

Related errors

Browse the full signature error database