Skip to content

Commit e08ce8c

Browse files
feat: add default Authorization Bearer header and clean up legacy auth
- Provide "Authorization: Bearer " as default starting header - Remove legacy auth props from components - Centralize migration logic and fix localStorage cleanup - Update tests for new auth architecture
1 parent f36c649 commit e08ce8c

File tree

7 files changed

+45
-62
lines changed

7 files changed

+45
-62
lines changed

client/eslint.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ export default tseslint.config(
2323
"warn",
2424
{ allowConstantExport: true },
2525
],
26-
"@typescript-eslint/no-unused-vars": [
27-
"error",
28-
{ argsIgnorePattern: "^_" },
29-
],
3026
},
3127
},
3228
);

client/src/App.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@ const App = () => {
154154
return migrateFromLegacyAuth(legacyToken, legacyHeaderName);
155155
}
156156

157-
return [];
157+
// Default to Authorization: Bearer as the most common case
158+
return [
159+
{
160+
name: "Authorization",
161+
value: "Bearer ",
162+
enabled: true,
163+
},
164+
];
158165
});
159166

160167
const [pendingSampleRequests, setPendingSampleRequests] = useState<
@@ -243,8 +250,6 @@ const App = () => {
243250
args,
244251
sseUrl,
245252
env,
246-
bearerToken,
247-
headerName,
248253
customHeaders,
249254
oauthClientId,
250255
oauthScope,
@@ -334,11 +339,19 @@ const App = () => {
334339
}, [transportType]);
335340

336341
useEffect(() => {
337-
localStorage.setItem("lastBearerToken", bearerToken);
342+
if (bearerToken) {
343+
localStorage.setItem("lastBearerToken", bearerToken);
344+
} else {
345+
localStorage.removeItem("lastBearerToken");
346+
}
338347
}, [bearerToken]);
339348

340349
useEffect(() => {
341-
localStorage.setItem("lastHeaderName", headerName);
350+
if (headerName) {
351+
localStorage.setItem("lastHeaderName", headerName);
352+
} else {
353+
localStorage.removeItem("lastHeaderName");
354+
}
342355
}, [headerName]);
343356

344357
useEffect(() => {
@@ -858,10 +871,6 @@ const App = () => {
858871
setEnv={setEnv}
859872
config={config}
860873
setConfig={setConfig}
861-
bearerToken={bearerToken}
862-
setBearerToken={setBearerToken}
863-
headerName={headerName}
864-
setHeaderName={setHeaderName}
865874
customHeaders={customHeaders}
866875
setCustomHeaders={setCustomHeaders}
867876
oauthClientId={oauthClientId}

client/src/components/Sidebar.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ interface SidebarProps {
5353
setSseUrl: (url: string) => void;
5454
env: Record<string, string>;
5555
setEnv: (env: Record<string, string>) => void;
56-
// Legacy auth props (for backward compatibility)
57-
bearerToken: string;
58-
setBearerToken: (token: string) => void;
59-
headerName?: string;
60-
setHeaderName?: (name: string) => void;
61-
// New custom headers support
56+
// Custom headers support
6257
customHeaders: CustomHeadersType;
6358
setCustomHeaders: (headers: CustomHeadersType) => void;
6459
oauthClientId: string;
@@ -86,10 +81,6 @@ const Sidebar = ({
8681
setSseUrl,
8782
env,
8883
setEnv,
89-
bearerToken: _bearerToken,
90-
setBearerToken: _setBearerToken,
91-
headerName: _headerName,
92-
setHeaderName: _setHeaderName,
9384
customHeaders,
9485
setCustomHeaders,
9586
oauthClientId,

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
render,
3-
screen,
4-
fireEvent,
5-
act,
6-
waitFor,
7-
} from "@testing-library/react";
1+
import { render, screen, fireEvent, act } from "@testing-library/react";
82
import "@testing-library/jest-dom";
93
import { describe, it, beforeEach, jest } from "@jest/globals";
104
import Sidebar from "../Sidebar";
@@ -54,10 +48,6 @@ describe("Sidebar", () => {
5448
setOauthScope: jest.fn(),
5549
env: {},
5650
setEnv: jest.fn(),
57-
bearerToken: "",
58-
setBearerToken: jest.fn(),
59-
headerName: "",
60-
setHeaderName: jest.fn(),
6151
customHeaders: [],
6252
setCustomHeaders: jest.fn(),
6353
onConnect: jest.fn(),

client/src/lib/hooks/__tests__/useConnection.test.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,17 @@ describe("useConnection", () => {
649649
});
650650

651651
test("preserves server Authorization header when proxy auth is configured", async () => {
652+
const customHeaders: CustomHeaders = [
653+
{
654+
name: "Authorization",
655+
value: "Bearer server-auth-token",
656+
enabled: true,
657+
},
658+
];
659+
652660
const propsWithBothAuth = {
653661
...defaultProps,
654-
bearerToken: "server-auth-token",
662+
customHeaders,
655663
config: {
656664
...DEFAULT_INSPECTOR_CONFIG,
657665
MCP_PROXY_AUTH_TOKEN: {
@@ -811,14 +819,18 @@ describe("useConnection", () => {
811819
expect(headers).not.toHaveProperty("X-Disabled");
812820
});
813821

814-
test("migrates from legacy bearerToken and headerName", async () => {
815-
const propsWithLegacyAuth = {
822+
test("handles migrated legacy auth via custom headers", async () => {
823+
// Simulate what App.tsx would do - migrate legacy auth to custom headers
824+
const customHeaders: CustomHeaders = [
825+
{ name: "X-Custom-Auth", value: "legacy-token", enabled: true },
826+
];
827+
828+
const propsWithMigratedAuth = {
816829
...defaultProps,
817-
bearerToken: "legacy-token",
818-
headerName: "X-Custom-Auth",
830+
customHeaders,
819831
};
820832

821-
const { result } = renderHook(() => useConnection(propsWithLegacyAuth));
833+
const { result } = renderHook(() => useConnection(propsWithMigratedAuth));
822834

823835
await act(async () => {
824836
await result.current.connect();

client/src/lib/hooks/useConnection.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,15 @@ import {
5757
import { getMCPServerRequestTimeout } from "@/utils/configUtils";
5858
import { InspectorConfig } from "../configurationTypes";
5959
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
60-
import { CustomHeaders, migrateFromLegacyAuth } from "../types/customHeaders";
60+
import { CustomHeaders } from "../types/customHeaders";
6161

6262
interface UseConnectionOptions {
6363
transportType: "stdio" | "sse" | "streamable-http";
6464
command: string;
6565
args: string;
6666
sseUrl: string;
6767
env: Record<string, string>;
68-
// Legacy auth support (for backward compatibility)
69-
bearerToken?: string;
70-
headerName?: string;
71-
// New custom headers support
68+
// Custom headers support
7269
customHeaders?: CustomHeaders;
7370
oauthClientId?: string;
7471
oauthScope?: string;
@@ -90,8 +87,6 @@ export function useConnection({
9087
args,
9188
sseUrl,
9289
env,
93-
bearerToken,
94-
headerName,
9590
customHeaders,
9691
oauthClientId,
9792
oauthScope,
@@ -384,16 +379,8 @@ export function useConnection({
384379
// Create an auth provider with the current server URL
385380
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
386381

387-
// Handle custom headers (new approach) or legacy auth (backward compatibility)
388-
let finalHeaders: CustomHeaders = [];
389-
390-
if (customHeaders && customHeaders.length > 0) {
391-
// Use new custom headers approach
392-
finalHeaders = customHeaders;
393-
} else if (bearerToken || headerName) {
394-
// Migrate from legacy auth approach
395-
finalHeaders = migrateFromLegacyAuth(bearerToken, headerName);
396-
}
382+
// Use custom headers (migration is handled in App.tsx)
383+
let finalHeaders: CustomHeaders = customHeaders || [];
397384

398385
// Add OAuth token if available and no custom headers are set
399386
if (finalHeaders.length === 0) {

client/src/lib/types/customHeaders.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ export const migrateFromLegacyAuth = (
5858
bearerToken?: string,
5959
headerName?: string,
6060
): CustomHeaders => {
61-
if (!bearerToken) {
62-
return [];
63-
}
64-
65-
return [createHeaderFromBearerToken(bearerToken, headerName)];
61+
return bearerToken
62+
? [createHeaderFromBearerToken(bearerToken, headerName)]
63+
: [];
6664
};

0 commit comments

Comments
 (0)