Skip to content

Commit 0ccd44c

Browse files
committed
Fix RFC 8414 metadata URL construction and add asMetadataUrl validation in callback
- buildMetadataUrls: insert .well-known/oauth-authorization-server between origin and path per RFC 8414 §3, instead of appending to the end. Fixes discovery for path-based issuers (e.g. multi-tenant Azure AD, Auth0). - Callback route: add !cached.asMetadataUrl to the validation guard, consistent with tryRefreshAfterInvalidToken in the probe route.
1 parent 5da08f9 commit 0ccd44c

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

apps/web/app/api/settings/mcp/connect/callback/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export async function GET(request: Request): Promise<Response> {
244244
}
245245

246246
const cached = getMcpServerSecret(serverKey);
247-
if (!cached || !cached.codeVerifier || !cached.redirectUri) {
247+
if (!cached || !cached.codeVerifier || !cached.redirectUri || !cached.asMetadataUrl) {
248248
return renderResultPage(
249249
{
250250
kind: "error",

apps/web/lib/mcp-oauth.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,15 @@ async function fetchAuthorizationServerMetadata(
261261
}
262262

263263
function buildMetadataUrls(issuer: string): string[] {
264-
const trimmed = issuer.endsWith("/") ? issuer.slice(0, -1) : issuer;
264+
// RFC 8414 §3: insert /.well-known/oauth-authorization-server between the
265+
// origin and the path, e.g. https://example.com/tenant becomes
266+
// https://example.com/.well-known/oauth-authorization-server/tenant
267+
const url = new URL(issuer);
268+
const path = url.pathname.replace(/\/+$/, "");
265269
return [
266-
`${trimmed}/.well-known/oauth-authorization-server`,
267-
`${trimmed}/.well-known/openid-configuration`,
270+
`${url.origin}/.well-known/oauth-authorization-server${path}`,
271+
// OIDC Discovery appends to the issuer per OpenID Connect Discovery §4.
272+
`${url.origin}${path}/.well-known/openid-configuration`,
268273
];
269274
}
270275

0 commit comments

Comments
 (0)