From b99b3d29d9b9ed210acbe1259b42ea4671524cea Mon Sep 17 00:00:00 2001 From: 2underscores Date: Mon, 28 Jul 2025 20:18:18 +1000 Subject: [PATCH] Using static client data as DCR fallback --- client/src/lib/oauth-state-machine.ts | 36 ++++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/client/src/lib/oauth-state-machine.ts b/client/src/lib/oauth-state-machine.ts index 5078cfe4..758deb23 100644 --- a/client/src/lib/oauth-state-machine.ts +++ b/client/src/lib/oauth-state-machine.ts @@ -88,16 +88,34 @@ export const oauthTransitions: Record = { clientMetadata.scope = scopesSupported.join(" "); } - const fullInformation = await registerClient(context.serverUrl, { - metadata, - clientMetadata, - }); + // Try DCR first, with static client as fallback + try { + const fullInformation = await registerClient(context.serverUrl, { + metadata, + clientMetadata, + }); - context.provider.saveClientInformation(fullInformation); - context.updateState({ - oauthClientInfo: fullInformation, - oauthStep: "authorization_redirect", - }); + context.provider.saveClientInformation(fullInformation); + context.updateState({ + oauthClientInfo: fullInformation, + oauthStep: "authorization_redirect", + }); + console.log({ fullInformation }); + return; + } catch (dcrError) { + console.error(dcrError); + + // DCR failed, fallback to preregistered client + const existingClientInfo = await context.provider.clientInformation(); + if (!existingClientInfo) { + console.error("Neither dynamic client registration or preregistered client information was found"); + throw dcrError; + } + context.updateState({ + oauthClientInfo: existingClientInfo, + oauthStep: "authorization_redirect", + }); + } }, },