Use new auth svr discovery method from latest auth SDK
This commit is contained in:
parent
113b612b99
commit
9ef2a6c22d
4 changed files with 26 additions and 19 deletions
|
|
@ -36,7 +36,7 @@ const mockOAuthClientInfo = {
|
||||||
// Mock MCP SDK functions - must be before imports
|
// Mock MCP SDK functions - must be before imports
|
||||||
jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
|
jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
|
||||||
auth: jest.fn(),
|
auth: jest.fn(),
|
||||||
discoverOAuthMetadata: jest.fn(),
|
discoverAuthorizationServerMetadata: jest.fn(),
|
||||||
registerClient: jest.fn(),
|
registerClient: jest.fn(),
|
||||||
startAuthorization: jest.fn(),
|
startAuthorization: jest.fn(),
|
||||||
exchangeAuthorization: jest.fn(),
|
exchangeAuthorization: jest.fn(),
|
||||||
|
|
@ -46,7 +46,7 @@ jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
|
||||||
|
|
||||||
// Import the functions to get their types
|
// Import the functions to get their types
|
||||||
import {
|
import {
|
||||||
discoverOAuthMetadata,
|
discoverAuthorizationServerMetadata,
|
||||||
registerClient,
|
registerClient,
|
||||||
startAuthorization,
|
startAuthorization,
|
||||||
exchangeAuthorization,
|
exchangeAuthorization,
|
||||||
|
|
@ -57,9 +57,10 @@ import { OAuthMetadata } from "@modelcontextprotocol/sdk/shared/auth.js";
|
||||||
import { EMPTY_DEBUGGER_STATE } from "@/lib/auth-types";
|
import { EMPTY_DEBUGGER_STATE } from "@/lib/auth-types";
|
||||||
|
|
||||||
// Type the mocked functions properly
|
// Type the mocked functions properly
|
||||||
const mockDiscoverOAuthMetadata = discoverOAuthMetadata as jest.MockedFunction<
|
const mockDiscoverAuthorizationServerMetadata =
|
||||||
typeof discoverOAuthMetadata
|
discoverAuthorizationServerMetadata as jest.MockedFunction<
|
||||||
>;
|
typeof discoverAuthorizationServerMetadata
|
||||||
|
>;
|
||||||
const mockRegisterClient = registerClient as jest.MockedFunction<
|
const mockRegisterClient = registerClient as jest.MockedFunction<
|
||||||
typeof registerClient
|
typeof registerClient
|
||||||
>;
|
>;
|
||||||
|
|
@ -102,7 +103,9 @@ describe("AuthDebugger", () => {
|
||||||
// Suppress console errors in tests to avoid JSDOM navigation noise
|
// Suppress console errors in tests to avoid JSDOM navigation noise
|
||||||
jest.spyOn(console, "error").mockImplementation(() => {});
|
jest.spyOn(console, "error").mockImplementation(() => {});
|
||||||
|
|
||||||
mockDiscoverOAuthMetadata.mockResolvedValue(mockOAuthMetadata);
|
mockDiscoverAuthorizationServerMetadata.mockResolvedValue(
|
||||||
|
mockOAuthMetadata,
|
||||||
|
);
|
||||||
mockRegisterClient.mockResolvedValue(mockOAuthClientInfo);
|
mockRegisterClient.mockResolvedValue(mockOAuthClientInfo);
|
||||||
mockDiscoverOAuthProtectedResourceMetadata.mockRejectedValue(
|
mockDiscoverOAuthProtectedResourceMetadata.mockRejectedValue(
|
||||||
new Error("No protected resource metadata found"),
|
new Error("No protected resource metadata found"),
|
||||||
|
|
@ -203,7 +206,7 @@ describe("AuthDebugger", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Should first discover and save OAuth metadata
|
// Should first discover and save OAuth metadata
|
||||||
expect(mockDiscoverOAuthMetadata).toHaveBeenCalledWith(
|
expect(mockDiscoverAuthorizationServerMetadata).toHaveBeenCalledWith(
|
||||||
new URL("https://example.com/"),
|
new URL("https://example.com/"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -216,7 +219,7 @@ describe("AuthDebugger", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show error when quick OAuth flow fails to discover metadata", async () => {
|
it("should show error when quick OAuth flow fails to discover metadata", async () => {
|
||||||
mockDiscoverOAuthMetadata.mockRejectedValue(
|
mockDiscoverAuthorizationServerMetadata.mockRejectedValue(
|
||||||
new Error("Metadata discovery failed"),
|
new Error("Metadata discovery failed"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -362,7 +365,7 @@ describe("AuthDebugger", () => {
|
||||||
fireEvent.click(screen.getByText("Continue"));
|
fireEvent.click(screen.getByText("Continue"));
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(mockDiscoverOAuthMetadata).toHaveBeenCalledWith(
|
expect(mockDiscoverAuthorizationServerMetadata).toHaveBeenCalledWith(
|
||||||
new URL("https://example.com/"),
|
new URL("https://example.com/"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -509,7 +512,9 @@ describe("AuthDebugger", () => {
|
||||||
mockDiscoverOAuthProtectedResourceMetadata.mockResolvedValue(
|
mockDiscoverOAuthProtectedResourceMetadata.mockResolvedValue(
|
||||||
mockResourceMetadata,
|
mockResourceMetadata,
|
||||||
);
|
);
|
||||||
mockDiscoverOAuthMetadata.mockResolvedValue(mockOAuthMetadata);
|
mockDiscoverAuthorizationServerMetadata.mockResolvedValue(
|
||||||
|
mockOAuthMetadata,
|
||||||
|
);
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
renderAuthDebugger({
|
renderAuthDebugger({
|
||||||
|
|
@ -563,7 +568,9 @@ describe("AuthDebugger", () => {
|
||||||
// Mock failed metadata discovery
|
// Mock failed metadata discovery
|
||||||
mockDiscoverOAuthProtectedResourceMetadata.mockRejectedValue(mockError);
|
mockDiscoverOAuthProtectedResourceMetadata.mockRejectedValue(mockError);
|
||||||
// But OAuth metadata should still work with the original URL
|
// But OAuth metadata should still work with the original URL
|
||||||
mockDiscoverOAuthMetadata.mockResolvedValue(mockOAuthMetadata);
|
mockDiscoverAuthorizationServerMetadata.mockResolvedValue(
|
||||||
|
mockOAuthMetadata,
|
||||||
|
);
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
renderAuthDebugger({
|
renderAuthDebugger({
|
||||||
|
|
@ -603,7 +610,7 @@ describe("AuthDebugger", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Verify that regular OAuth metadata discovery was still called
|
// Verify that regular OAuth metadata discovery was still called
|
||||||
expect(mockDiscoverOAuthMetadata).toHaveBeenCalledWith(
|
expect(mockDiscoverAuthorizationServerMetadata).toHaveBeenCalledWith(
|
||||||
new URL("https://example.com/"),
|
new URL("https://example.com/"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { OAuthStep, AuthDebuggerState } from "./auth-types";
|
import { OAuthStep, AuthDebuggerState } from "./auth-types";
|
||||||
import { DebugInspectorOAuthClientProvider } from "./auth";
|
import { DebugInspectorOAuthClientProvider } from "./auth";
|
||||||
import {
|
import {
|
||||||
discoverOAuthMetadata,
|
discoverAuthorizationServerMetadata,
|
||||||
registerClient,
|
registerClient,
|
||||||
startAuthorization,
|
startAuthorization,
|
||||||
exchangeAuthorization,
|
exchangeAuthorization,
|
||||||
|
|
@ -56,7 +56,7 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
|
||||||
resourceMetadata ?? undefined,
|
resourceMetadata ?? undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
const metadata = await discoverOAuthMetadata(authServerUrl);
|
const metadata = await discoverAuthorizationServerMetadata(authServerUrl);
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
throw new Error("Failed to discover OAuth metadata");
|
throw new Error("Failed to discover OAuth metadata");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
package-lock.json
generated
8
package-lock.json
generated
|
|
@ -17,7 +17,7 @@
|
||||||
"@modelcontextprotocol/inspector-cli": "^0.16.3",
|
"@modelcontextprotocol/inspector-cli": "^0.16.3",
|
||||||
"@modelcontextprotocol/inspector-client": "^0.16.3",
|
"@modelcontextprotocol/inspector-client": "^0.16.3",
|
||||||
"@modelcontextprotocol/inspector-server": "^0.16.3",
|
"@modelcontextprotocol/inspector-server": "^0.16.3",
|
||||||
"@modelcontextprotocol/sdk": "^1.17.0",
|
"@modelcontextprotocol/sdk": "^1.17.2",
|
||||||
"concurrently": "^9.2.0",
|
"concurrently": "^9.2.0",
|
||||||
"open": "^10.2.0",
|
"open": "^10.2.0",
|
||||||
"shell-quote": "^1.8.3",
|
"shell-quote": "^1.8.3",
|
||||||
|
|
@ -1999,9 +1999,9 @@
|
||||||
"link": true
|
"link": true
|
||||||
},
|
},
|
||||||
"node_modules/@modelcontextprotocol/sdk": {
|
"node_modules/@modelcontextprotocol/sdk": {
|
||||||
"version": "1.17.0",
|
"version": "1.17.2",
|
||||||
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.17.2.tgz",
|
||||||
"integrity": "sha512-qFfbWFA7r1Sd8D697L7GkTd36yqDuTkvz0KfOGkgXR8EUhQn3/EDNIR/qUdQNMT8IjmasBvHWuXeisxtXTQT2g==",
|
"integrity": "sha512-EFLRNXR/ixpXQWu6/3Cu30ndDFIFNaqUXcTqsGebujeMan9FzhAaFFswLRiFj61rgygDRr8WO1N+UijjgRxX9g==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ajv": "^6.12.6",
|
"ajv": "^6.12.6",
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@
|
||||||
"@modelcontextprotocol/inspector-cli": "^0.16.3",
|
"@modelcontextprotocol/inspector-cli": "^0.16.3",
|
||||||
"@modelcontextprotocol/inspector-client": "^0.16.3",
|
"@modelcontextprotocol/inspector-client": "^0.16.3",
|
||||||
"@modelcontextprotocol/inspector-server": "^0.16.3",
|
"@modelcontextprotocol/inspector-server": "^0.16.3",
|
||||||
"@modelcontextprotocol/sdk": "^1.17.0",
|
"@modelcontextprotocol/sdk": "^1.17.2",
|
||||||
"concurrently": "^9.2.0",
|
"concurrently": "^9.2.0",
|
||||||
"open": "^10.2.0",
|
"open": "^10.2.0",
|
||||||
"shell-quote": "^1.8.3",
|
"shell-quote": "^1.8.3",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue