Skip to content

Commit 82858be

Browse files
committed
show proper authserverurl
1 parent 73fde03 commit 82858be

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed

client/src/components/OAuthFlowProgress.tsx

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -128,38 +128,54 @@ export const OAuthFlowProgress = ({
128128
label="Metadata Discovery"
129129
{...getStepProps("metadata_discovery")}
130130
>
131-
{authState.resourceMetadata && (
132-
<details className="text-xs mt-2">
133-
<summary className="cursor-pointer text-muted-foreground font-medium">
134-
Retrieved OAuth Resource Metadata from {(new URL('/.well-known/oauth-protected-resource', serverUrl)).href}
135-
</summary>
136-
<pre className="mt-2 p-2 bg-muted rounded-md overflow-auto max-h-[300px]">
137-
{JSON.stringify(authState.resourceMetadata, null, 2)}
138-
</pre>
139-
</details>
140-
)}
141-
{authState.resourceMetadataError && (
142-
<div className="mt-2 p-3 border border-yellow-300 bg-yellow-50 rounded-md">
143-
<p className="text-sm font-small text-yellow-700">
144-
Failed to retrieve resource metadata, falling back to /.well-known/oauth-authorization-server:
145-
</p>
146-
<p className="text-xs text-yellow-600 mt-1">
147-
{authState.resourceMetadataError.message}
148-
{authState.resourceMetadataError instanceof TypeError
149-
? " (This could indicate the endpoint doesn't exist or does not have CORS configured)"
150-
: authState.resourceMetadataError['status'] && ` (${authState.resourceMetadataError['status']})`}
151-
</p>
152-
</div>
153-
)}
154131
{provider.getServerMetadata() && (
155132
<details className="text-xs mt-2">
156133
<summary className="cursor-pointer text-muted-foreground font-medium">
157-
Retrieved OAuth Metadata from {serverUrl}
158-
/.well-known/oauth-authorization-server
134+
OAuth Metadata Sources
135+
{!authState.resourceMetadata && " ℹ️"}
159136
</summary>
160-
<pre className="mt-2 p-2 bg-muted rounded-md overflow-auto max-h-[300px]">
161-
{JSON.stringify(provider.getServerMetadata(), null, 2)}
162-
</pre>
137+
138+
{authState.resourceMetadata && (
139+
<div className="mt-2">
140+
<p className="font-medium">Resource Metadata:</p>
141+
<p className="text-xs text-muted-foreground">
142+
From {new URL('/.well-known/oauth-protected-resource', serverUrl).href}
143+
</p>
144+
<pre className="mt-2 p-2 bg-muted rounded-md overflow-auto max-h-[300px]">
145+
{JSON.stringify(authState.resourceMetadata, null, 2)}
146+
</pre>
147+
</div>
148+
)}
149+
150+
{authState.resourceMetadataError && (
151+
<div className="mt-2 p-3 border border-blue-300 bg-blue-50 rounded-md">
152+
<p className="text-sm font-medium text-blue-700">
153+
ℹ️ No resource metadata available from {' '}
154+
<a href={new URL('/.well-known/oauth-protected-resource', serverUrl).href} target="_blank" rel="noopener noreferrer" className="text-blue-500 hover:text-blue-700">
155+
{new URL('/.well-known/oauth-protected-resource', serverUrl).href}
156+
</a>
157+
</p>
158+
<p className="text-xs text-blue-600 mt-1">
159+
Resource metadata was added in the <a href="https://modelcontextprotocol.io/specification/draft/basic/authorization#2-3-1-authorization-server-location">2025-DRAFT-v2 specification update</a>
160+
<br />
161+
{authState.resourceMetadataError.message}
162+
{authState.resourceMetadataError instanceof TypeError
163+
&& " (This could indicate the endpoint doesn't exist or does not have CORS configured)"}
164+
</p>
165+
</div>
166+
)}
167+
168+
{provider.getServerMetadata() && (
169+
<div className="mt-2">
170+
<p className="font-medium">Authorization Server Metadata:</p>
171+
{authState.authServerUrl && <p className="text-xs text-muted-foreground">
172+
From {new URL('/.well-known/oauth-authorization-server', authState.authServerUrl).href}
173+
</p>}
174+
<pre className="mt-2 p-2 bg-muted rounded-md overflow-auto max-h-[300px]">
175+
{JSON.stringify(provider.getServerMetadata(), null, 2)}
176+
</pre>
177+
</div>
178+
)}
163179
</details>
164180
)}
165181
</OAuthStepDetails>

client/src/lib/auth-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface AuthDebuggerState {
3131
oauthStep: OAuthStep;
3232
resourceMetadata: OAuthProtectedResourceMetadata | null;
3333
resourceMetadataError: Error | { status: number; statusText: string; message: string } | null;
34+
authServerUrl: URL | null;
3435
oauthMetadata: OAuthMetadata | null;
3536
oauthClientInfo: OAuthClientInformationFull | OAuthClientInformation | null;
3637
authorizationUrl: string | null;
@@ -48,6 +49,7 @@ export const EMPTY_DEBUGGER_STATE: AuthDebuggerState = {
4849
oauthMetadata: null,
4950
resourceMetadata: null,
5051
resourceMetadataError: null,
52+
authServerUrl: null,
5153
oauthClientInfo: null,
5254
authorizationUrl: null,
5355
authorizationCode: "",

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
2626
metadata_discovery: {
2727
canTransition: async () => true,
2828
execute: async (context) => {
29-
let authServerUrl = context.serverUrl;
29+
let authServerUrl = new URL(context.serverUrl);
3030
let resourceMetadata: OAuthProtectedResourceMetadata | null = null;
3131
let resourceMetadataError: Error | null = null;
3232
try {
3333
resourceMetadata = await discoverOAuthProtectedResourceMetadata(context.serverUrl);
3434
if (resourceMetadata && resourceMetadata.authorization_servers?.length) {
35-
authServerUrl = resourceMetadata.authorization_servers[0];
35+
authServerUrl = new URL(resourceMetadata.authorization_servers[0]);
3636
}
3737
} catch (e) {
3838
console.info(`Failed to find protected resource metadata: ${e}`);
@@ -53,6 +53,7 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
5353
context.updateState({
5454
resourceMetadata,
5555
resourceMetadataError,
56+
authServerUrl,
5657
oauthMetadata: parsedMetadata,
5758
oauthStep: "client_registration",
5859
});

0 commit comments

Comments
 (0)