fix: read the SDK's own discovery state instead of a marker of our own

Copilot review (#2287), two findings — and taken together they said the marker
was the wrong mechanism, so this removes it rather than patching it again:

- A transient failure in our CIMD preflight recorded no marker, so a *successful*
  SDK fallback discovery that advertised CIMD was still stored as `dcr`.
- `existing` and `existingKind` could describe different registrations, because
  `clientInformation()` answers preregistered-first while `clientRegistrationKind()`
  prefers the issuer's dynamic slot.

SDK v2 `auth()` persists the authorization-server metadata via
`saveDiscoveryState` *before* it reads or writes client information, and it takes
its URL-based-client-ID branch — rather than `registerClient` — exactly when that
metadata advertises `client_id_metadata_document_supported` and a
`clientMetadataUrl` is configured. So the branch is not inferred at all now: it is
read back from the state the SDK itself just wrote.

`resolveSdkRegistrationKind` becomes two cases. A save for an issuer that already
has a registration under this `client_id` is a back-stamp, answered by that
registration's recorded kind — so an existing DCR on the metadata URL stays
`dcr`. A save for an issuer with none is a new registration, answered by the
discovery state, guarded on the metadata describing that same issuer.

This drops `cimdClientMetadataUrl` and its storage accessors entirely, and
restores `ensureCimdClientRegistration` to a plain issuer-bound pre-registration.
Invalid-client recovery, second-issuer CIMD, second-issuer DCR minting the
metadata URL, and preflight failure are all consequences of the two cases rather
than separate mechanisms.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lmj6X2epWpPE7ScdSKQmtA
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-09-07 02:03:12 -04:00
commit 6273790077

View file

@ -81,23 +81,6 @@ export interface OAuthStorage {
issuer?: string,
): Promise<OAuthClientRegistrationKind | undefined>;
/**
* The CIMD client-metadata URL this authorization server was confirmed to
* accept as a `client_id`. Survives {@link clearClientInformation}, because it
* records a property of the AS rather than a credential (#2242).
*/
getCimdClientMetadataUrl(
serverUrl: string,
issuer?: string,
): Promise<string | undefined>;
/** Write (or, with `undefined`, clear) the marker above for one issuer. */
saveCimdClientMetadataUrl(
serverUrl: string,
issuer: string,
clientMetadataUrl: string | undefined,
): Promise<void>;
/**
* Save client information (dynamically registered)
*/