Merge pull request #175 from avi1mizrahi/main

Add Bearer Token Support
This commit is contained in:
Justin Spahr-Summers
2025-03-11 10:50:51 +00:00
committed by GitHub
4 changed files with 63 additions and 12 deletions

View File

@@ -38,6 +38,7 @@ interface UseConnectionOptions {
sseUrl: string;
env: Record<string, string>;
proxyServerUrl: string;
bearerToken?: string;
requestTimeout?: number;
onNotification?: (notification: Notification) => void;
onStdErrNotification?: (notification: Notification) => void;
@@ -58,6 +59,7 @@ export function useConnection({
sseUrl,
env,
proxyServerUrl,
bearerToken,
requestTimeout = DEFAULT_REQUEST_TIMEOUT_MSEC,
onNotification,
onStdErrNotification,
@@ -229,9 +231,11 @@ export function useConnection({
// Inject auth manually instead of using SSEClientTransport, because we're
// proxying through the inspector server first.
const headers: HeadersInit = {};
const tokens = await authProvider.tokens();
if (tokens) {
headers["Authorization"] = `Bearer ${tokens.access_token}`;
// Use manually provided bearer token if available, otherwise use OAuth tokens
const token = bearerToken || (await authProvider.tokens())?.access_token;
if (token) {
headers["Authorization"] = `Bearer ${token}`;
}
const clientTransport = new SSEClientTransport(backendUrl, {