Skip to content

Commit 678b3e3

Browse files
committed
feat: allow OIDC configuration for OAuth server
1 parent 1878143 commit 678b3e3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/client/auth.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ export interface OAuthClientProvider {
7171
* the authorization result.
7272
*/
7373
codeVerifier(): string | Promise<string>;
74+
75+
/**
76+
* Use OpenID Provider configuration information for authorization
77+
* server metadata.
78+
* https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig
79+
*/
80+
useOidcProviderConfiguration?(): boolean | Promise<boolean>;
7481
}
7582

7683
export type AuthResult = "AUTHORIZED" | "REDIRECT";
@@ -111,7 +118,9 @@ export async function auth(
111118
console.warn("Could not load OAuth Protected Resource metadata, falling back to /.well-known/oauth-authorization-server", error)
112119
}
113120

114-
const metadata = await discoverOAuthMetadata(authorizationServerUrl);
121+
const metadata = await discoverOAuthMetadata(authorizationServerUrl, {
122+
useOidcConfig: await provider.useOidcProviderConfiguration?.()
123+
});
115124

116125
// Handle client registration if needed
117126
let clientInformation = await Promise.resolve(provider.clientInformation());
@@ -267,9 +276,15 @@ export async function discoverOAuthProtectedResourceMetadata(
267276
*/
268277
export async function discoverOAuthMetadata(
269278
authorizationServerUrl: string | URL,
270-
opts?: { protocolVersion?: string },
279+
opts?: {
280+
protocolVersion?: string
281+
useOidcConfig?: boolean
282+
},
271283
): Promise<OAuthMetadata | undefined> {
272-
const url = new URL("/.well-known/oauth-authorization-server", authorizationServerUrl);
284+
const metadataPath = opts?.useOidcConfig ?
285+
"openid-configuration" :
286+
"oauth-authorization-server";
287+
const url = new URL(`/.well-known/${metadataPath}`, authorizationServerUrl);
273288
let response: Response;
274289
try {
275290
response = await fetch(url, {

0 commit comments

Comments
 (0)