Skip to content

Commit abcf91b

Browse files
authored
Fix oauth-protected-resource to also be path aware
1 parent 1ac2e59 commit abcf91b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/client/auth.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ export async function discoverOAuthProtectedResourceMetadata(
261261
if (opts?.resourceMetadataUrl) {
262262
url = new URL(opts?.resourceMetadataUrl);
263263
} else {
264-
url = new URL("/.well-known/oauth-protected-resource", serverUrl);
264+
const issuer = new URL(serverUrl);
265+
const wellKnownPath = buildWellKnownPath('oauth-protected-resource', issuer.pathname);
266+
url = new URL(wellKnownPath, issuer);
265267
}
266268

267269
let response: Response;
@@ -318,8 +320,8 @@ async function fetchWithCorsRetry(
318320
/**
319321
* Constructs the well-known path for OAuth metadata discovery
320322
*/
321-
function buildWellKnownPath(pathname: string): string {
322-
let wellKnownPath = `/.well-known/oauth-authorization-server${pathname}`;
323+
function buildWellKnownPath(wellKnownPath: string, pathname: string): string {
324+
let wellKnownPath = `/.well-known/${wellKnownPath}${pathname}`;
323325
if (pathname.endsWith('/')) {
324326
// Strip trailing slash from pathname to avoid double slashes
325327
wellKnownPath = wellKnownPath.slice(0, -1);
@@ -361,7 +363,7 @@ export async function discoverOAuthMetadata(
361363
const protocolVersion = opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION;
362364

363365
// Try path-aware discovery first (RFC 8414 compliant)
364-
const wellKnownPath = buildWellKnownPath(issuer.pathname);
366+
const wellKnownPath = buildWellKnownPath('oauth-authorization-server', issuer.pathname);
365367
const pathAwareUrl = new URL(wellKnownPath, issuer);
366368
let response = await tryMetadataDiscovery(pathAwareUrl, protocolVersion);
367369

0 commit comments

Comments
 (0)