Skip to content

Commit b99b3d2

Browse files
committed
Using static client data as DCR fallback
1 parent aa6a98a commit b99b3d2

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

client/src/lib/oauth-state-machine.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,34 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
8888
clientMetadata.scope = scopesSupported.join(" ");
8989
}
9090

91-
const fullInformation = await registerClient(context.serverUrl, {
92-
metadata,
93-
clientMetadata,
94-
});
91+
// Try DCR first, with static client as fallback
92+
try {
93+
const fullInformation = await registerClient(context.serverUrl, {
94+
metadata,
95+
clientMetadata,
96+
});
9597

96-
context.provider.saveClientInformation(fullInformation);
97-
context.updateState({
98-
oauthClientInfo: fullInformation,
99-
oauthStep: "authorization_redirect",
100-
});
98+
context.provider.saveClientInformation(fullInformation);
99+
context.updateState({
100+
oauthClientInfo: fullInformation,
101+
oauthStep: "authorization_redirect",
102+
});
103+
console.log({ fullInformation });
104+
return;
105+
} catch (dcrError) {
106+
console.error(dcrError);
107+
108+
// DCR failed, fallback to preregistered client
109+
const existingClientInfo = await context.provider.clientInformation();
110+
if (!existingClientInfo) {
111+
console.error("Neither dynamic client registration or preregistered client information was found");
112+
throw dcrError;
113+
}
114+
context.updateState({
115+
oauthClientInfo: existingClientInfo,
116+
oauthStep: "authorization_redirect",
117+
});
118+
}
101119
},
102120
},
103121

0 commit comments

Comments
 (0)