feat(web,core): enterprise-managed authorization (EMA) (#1509) (#1512)

Adds enterprise-managed authorization (EMA): browser-side IdP login + RFC 8693 token-exchange and JWT-bearer resource-token mint, per-server EMA opt-in in Server Settings, IdP config in Client Settings, and IdP clientSecret keychain storage. Includes the v2/main merge and review follow-ups (400 on malformed client config; normalizeIdpIssuer import consolidation).
This commit is contained in:
Bob Dickinson 2026-06-24 19:15:12 -07:00 • committed by GitHub
commit 5de4e911e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -118,7 +118,7 @@ import {
UrlElicitationLoopError,
} from "./urlElicitation.js";
import { ToolCallCancelledError } from "./toolCallCancelledError.js";
import type { AuthGuidedState, OAuthStep } from "../auth/types.js";
import type { OAuthConnectionState, OAuthFlowState, OAuthStep } from "../auth/types.js";
import type { OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
import { silentLogger, type InspectorLogger } from "../logging/logger.js";
import { createFetchTracker } from "./fetchTracking.js";
@ -306,6 +306,8 @@ export class InspectorClient extends InspectorClientEventTarget {
return Promise.resolve();
},
initialConfig: oauthConfig,
enterpriseManagedAuth: options.enterpriseManagedAuth,
installEnterpriseManagedAuth: options.installEnterpriseManagedAuth,
dispatchOAuthStepChange: (detail) =>
this.dispatchTypedEvent("oauthStepChange", detail),
dispatchOAuthComplete: (detail) =>
@ -362,6 +364,11 @@ export class InspectorClient extends InspectorClientEventTarget {
},
};
}
if (options.oauth?.enterpriseManaged) {
capabilities.extensions = {
"io.modelcontextprotocol/enterprise-managed-authorization": {},
};
}
if (Object.keys(capabilities).length > 0) {
clientOptions.capabilities = capabilities;
}
@ -702,7 +709,21 @@ export class InspectorClient extends InspectorClientEventTarget {
};
const oauthManager = this.oauthManager;
if (this.isHttpOAuthConfig() && oauthManager) {
if (oauthManager.isEnterpriseManaged()) {
await oauthManager.trySilentEnterpriseManagedAuth();
}
const provider = await oauthManager.createOAuthProviderForTransport();
if (oauthManager.isEnterpriseManaged()) {
const tokens = await provider.tokens();
if (!tokens?.access_token) {
const err = new Error(
"Unauthorized: EMA resource access token unavailable",
) as Error & { status?: number; code?: number };
err.status = 401;
err.code = 401;
throw err;
}
}
transportOptions.authProvider = provider;
}
const { transport: baseTransport } = this.transportClientFactory(
@ -2655,7 +2676,7 @@ export class InspectorClient extends InspectorClientEventTarget {
* Initiates OAuth flow using SDK's auth() function (normal mode)
* Can be called directly by user or automatically triggered by 401 errors
*/
async authenticate(): Promise<URL> {
async authenticate(): Promise<URL | undefined> {
return this.ensureOAuthManager().authenticate();
}
@ -2733,17 +2754,30 @@ export class InspectorClient extends InspectorClientEventTarget {
}
/**
* Get current OAuth state machine state (for guided mode)
* In-memory OAuth flow snapshot (quick or guided). Undefined when no flow
* has run on this client instance; use {@link getOAuthState} for persisted
* authorization state.
*/
getOAuthState(): AuthGuidedState | undefined {
return this.oauthManager?.getOAuthState();
getOAuthFlowState(): OAuthFlowState | undefined {
return this.oauthManager?.getOAuthFlowState();
}
/**
* Get current OAuth step (for guided mode)
* Current step when an OAuth flow is active (quick or guided).
*/
getOAuthStep(): OAuthStep | undefined {
return this.oauthManager?.getOAuthStep();
getOAuthFlowStep(): OAuthStep | undefined {
return this.oauthManager?.getOAuthFlowStep();
}
/**
* Persisted OAuth authorization snapshot for this HTTP server (storage +
* config). Undefined for stdio transports or when OAuth is not configured.
*/
async getOAuthState(): Promise<OAuthConnectionState | undefined> {
if (!this.isHttpOAuthConfig() || !this.oauthManager) {
return undefined;
}
return this.oauthManager.getOAuthState();
}
/**