Skip to content

Commit 1b8d63e

Browse files
committed
add metadataServerUrl to discoverMetadataWithFallback to allow external AS
1 parent ea8caa9 commit 1b8d63e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/client/auth.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ describe("OAuth Authorization", () => {
17531753
mockFetch.mockImplementation((url) => {
17541754
const urlString = url.toString();
17551755

1756-
if (urlString === "https://my.resource.com/.well-known/oauth-protected-resource") {
1756+
if (urlString === "https://my.resource.com/.well-known/oauth-protected-resource/path/name") {
17571757
return Promise.resolve({
17581758
ok: true,
17591759
status: 200,
@@ -1800,7 +1800,7 @@ describe("OAuth Authorization", () => {
18001800
const calls = mockFetch.mock.calls;
18011801

18021802
// First call should be to PRM
1803-
expect(calls[0][0].toString()).toBe("https://my.resource.com/.well-known/oauth-protected-resource");
1803+
expect(calls[0][0].toString()).toBe("https://my.resource.com/.well-known/oauth-protected-resource/path/name");
18041804

18051805
// Second call should be to AS metadata with the path from serverUrl
18061806
expect(calls[1][0].toString()).toBe("https://auth.example.com/.well-known/oauth-authorization-server/path/name");

src/client/auth.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ function shouldAttemptFallback(response: Response | undefined, pathname: string)
471471
async function discoverMetadataWithFallback(
472472
serverUrl: string | URL,
473473
wellKnownType: 'oauth-authorization-server' | 'oauth-protected-resource',
474-
opts?: { protocolVersion?: string; metadataUrl?: string | URL },
474+
opts?: { protocolVersion?: string; metadataUrl?: string | URL, metadataServerUrl?: string | URL },
475475
): Promise<Response | undefined> {
476476
const issuer = new URL(serverUrl);
477477
const protocolVersion = opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION;
@@ -482,7 +482,7 @@ async function discoverMetadataWithFallback(
482482
} else {
483483
// Try path-aware discovery first
484484
const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname);
485-
url = new URL(wellKnownPath, issuer);
485+
url = new URL(wellKnownPath, opts?.metadataServerUrl ?? issuer);
486486
url.search = issuer.search;
487487
}
488488

@@ -525,9 +525,13 @@ export async function discoverOAuthMetadata(
525525
protocolVersion ??= LATEST_PROTOCOL_VERSION;
526526

527527
const response = await discoverMetadataWithFallback(
528-
authorizationServerUrl,
528+
issuer,
529+
// authorizationServerUrl,
529530
'oauth-authorization-server',
530-
{protocolVersion},
531+
{
532+
protocolVersion,
533+
metadataServerUrl: authorizationServerUrl,
534+
},
531535
);
532536

533537
if (!response || response.status === 404) {

0 commit comments

Comments
 (0)