Skip to content

Commit 8562cba

Browse files
committed
fixing tests and types
1 parent d6fed2a commit 8562cba

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

client/src/components/__tests__/AuthDebugger.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ describe("AuthDebugger", () => {
320320
isInitiatingAuth: false,
321321
resourceMetadata: null,
322322
resourceMetadataError: null,
323+
resource: null,
323324
oauthTokens: null,
324325
oauthStep: "metadata_discovery",
325326
latestError: null,

client/src/lib/auth-types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface AuthDebuggerState {
3030
oauthStep: OAuthStep;
3131
resourceMetadata: OAuthProtectedResourceMetadata | null;
3232
resourceMetadataError: Error | null;
33-
resource: string | null;
33+
resource: URL | null;
3434
authServerUrl: URL | null;
3535
oauthMetadata: OAuthMetadata | null;
3636
oauthClientInfo: OAuthClientInformationFull | OAuthClientInformation | null;
@@ -48,6 +48,7 @@ export const EMPTY_DEBUGGER_STATE: AuthDebuggerState = {
4848
oauthMetadata: null,
4949
resourceMetadata: null,
5050
resourceMetadataError: null,
51+
resource: null,
5152
authServerUrl: null,
5253
oauthClientInfo: null,
5354
authorizationUrl: null,

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import {
77
exchangeAuthorization,
88
discoverOAuthProtectedResourceMetadata,
99
} from "@modelcontextprotocol/sdk/client/auth.js";
10-
import {
11-
resourceUrlFromServerUrl
12-
} from "@modelcontextprotocol/sdk/shared/auth-utils.js";
10+
import { resourceUrlFromServerUrl } from "@modelcontextprotocol/sdk/shared/auth-utils.js";
1311
import {
1412
OAuthMetadataSchema,
1513
OAuthProtectedResourceMetadata,
@@ -51,11 +49,11 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
5149
}
5250
}
5351

54-
let resource: string| undefined;
52+
let resource: URL | undefined;
5553
if (resourceMetadata) {
56-
resource = resourceUrlFromServerUrl(context.serverUrl);
5754
// TODO: use SDK function selectResourceURL once version bump lands to be consistent
58-
if (resource !== resourceMetadata.resource)
55+
resource = resourceUrlFromServerUrl(new URL(context.serverUrl));
56+
if (resource.href !== resourceMetadata.resource) {
5957
resourceMetadataError = new Error(
6058
`Warning: metadata resource ${resourceMetadata.resource} does not match serverUrl ${context.serverUrl}`,
6159
);
@@ -126,7 +124,7 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
126124
clientInformation,
127125
redirectUrl: context.provider.redirectUrl,
128126
scope,
129-
resource: context.state.resource,
127+
resource: context.state.resource ?? undefined,
130128
},
131129
);
132130

@@ -177,7 +175,7 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
177175
authorizationCode: context.state.authorizationCode,
178176
codeVerifier,
179177
redirectUri: context.provider.redirectUrl,
180-
resource: context.state.resource,
178+
resource: context.state.resource ?? undefined,
181179
});
182180

183181
context.provider.saveTokens(tokens);

0 commit comments

Comments
 (0)