Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# The MCP callback needs the state of a pending login

- **Status:** Accepted
- **Revisions:** v1 2026-10-30 (initial)
- **Revisions:** v1 2026-10-30 (initial) · v2 2026-11-25 (public OIDC clients)
- **Deciders:** Vishnu Jain
- **Guard:** `McpCallbackServletTest` (`doGet_idTokenWithoutState_returns400AndIssuesNoCode`)
- **Related:** #29228, #36655, ADR:2026-10-23-mcp-sso-asks-consent-after-the-idp-round-trip
- **Related:** #29228, #36655, #38480, ADR:2026-10-23-mcp-sso-asks-consent-after-the-idp-round-trip

## Context

Expand All @@ -26,3 +26,33 @@ when its pending request has expired (10 minutes), and that login has to be rest
- A provider set up to return the ID token in the URL fragment cannot complete an MCP login; it
needs the authorization-code flow, as the web login does.
- Adding a second callback path again means repeating every check `handleCallback` makes.

## Amendment — public OIDC clients

For a public OIDC client, MCP uses the top-level client ID and discovers the provider at
`<authority>/.well-known/openid-configuration`. For Azure, the authority gains `/v2.0` if needed.
The public flow derives its own settings independently of the confidential `oidcConfiguration`.
The MCP base URL comes from the MCP settings, falling back to the system OpenMetadata URL.

If initial discovery fails, the public MCP handler waits one minute before trying again for the
same configuration. After the first success, the handler checks for endpoint changes on demand,
at most once per minute. If a refresh fails, sign-ins that need discovery receive that failure until
the next attempt. This bounds traffic during an outage. The issuer must match the initial document.
A provider can rotate endpoints while keeping that issuer. To switch issuers, reload the provider
configuration. For discovery, token exchanges and signing-key downloads, the server checks the
outbound URL before connecting and disables HTTP redirects. `PublicOidcConfigurationTest` covers
endpoint rotation, refusal of a changed issuer, recovery and redirect handling.

Register `<external MCP base URL>/mcp/callback` at the identity provider
for a server-side authorization-code exchange using the public client ID and S256 PKCE. Include
the deployment base path, if configured. OpenMetadata sends this same URI when it requests and
redeems the code. The browser application retains its own registered redirect. MCP requires a pending
login and asks for consent before issuing a grant.

A Microsoft Entra redirect registered as a single-page application requires a browser origin
during redemption. Keep the browser redirect registered for the SPA and configure the MCP redirect
for server-side redemption under the same public client ID. A browser-only registration
fails before consent. [Microsoft Entra authorization code flow](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#redirect-uris-for-single-page-apps)

`SsoMcpSignInChecksIT` exercises the provider exchange, the agent's first tool call and refusal
by a browser-only provider registration.
2 changes: 1 addition & 1 deletion docs/sso-integration-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ reports success.
| Session renewal | `SsoTokenRenewalIT` | RN-01 to RN-09, RN-12, RN-16 |
| Provider shapes (Okta, Google, Auth0, Cognito, Keycloak, Entra) | `SsoOidcProviderProfilesIT` | OC-02, OC-03, OP-01 per provider |
| MCP client sign-in, per recorded client profile | `SsoMcpClientProfilesIT` | confidential OIDC and the password form |
| MCP sign-in per provider shape, refusals and known gaps | `SsoMcpSignInChecksIT` | provider shapes, code replay, consent denial, cross-client refresh, no account, `gap...` |
| MCP sign-in per provider shape, refusals and known gaps | `SsoMcpSignInChecksIT` | public client sign-in with S256 PKCE, confidential provider shapes, code replay, consent denial, cross-client refresh, no account, `gap...` |

SAML, LDAP, identity resolution, role sync, settings changes, Test Login, multi-node sessions and
SCIM follow the same pattern and are added phase by phase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public static SecurityConfiguration publicOidc(
.withProviderName(PROVIDER_NAME)
.withClientType(ClientType.PUBLIC)
.withAuthority(provider.issuer())
.withClientId(MockOidcProvider.CLIENT_ID)
.withCallbackUrl(SsoServer.url(SsoServer.CALLBACK_PATH))
.withClientId(provider.clientId())
.withOidcConfiguration(null)
.withCallbackUrl(SsoServer.url(SsoServer.SPA_CALLBACK_PATH))
.withPublicKeyUrls(List.of(provider.jwksUri()));
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final class MockOidcProvider implements AutoCloseable {

private final MockHttp.LoopbackServer server;
private final OidcProviderProfile profile;
private final boolean publicClient;
private final String baseUrl;
private final String issuer;
private final MockOidcKeys keys = new MockOidcKeys();
Expand All @@ -65,13 +66,16 @@ public final class MockOidcProvider implements AutoCloseable {
private final AtomicReference<MockResponseGate> nextJwksGate = new AtomicReference<>();
private final AtomicReference<String> nextAuthorizationError = new AtomicReference<>();

private MockOidcProvider(MockHttp.LoopbackServer server, OidcProviderProfile profile) {
private MockOidcProvider(
MockHttp.LoopbackServer server, OidcProviderProfile profile, boolean publicClient) {
this.server = server;
this.profile = profile;
this.publicClient = publicClient;
this.baseUrl = server.localhostUrl();
this.issuer = profile.discoveryIssuer(baseUrl);
this.tokens = new MockOidcTokens(profile.tokenIssuer(baseUrl), CLIENT_ID, keys, profile);
this.tokenEndpoint = new MockOidcTokenEndpoint(tokens, journal, CLIENT_ID, CLIENT_SECRET);
this.tokens = new MockOidcTokens(profile.tokenIssuer(baseUrl), clientId(), keys, profile);
this.tokenEndpoint =
new MockOidcTokenEndpoint(tokens, journal, clientId(), publicClient ? null : CLIENT_SECRET);
}

public static MockOidcProvider start() {
Expand All @@ -80,11 +84,24 @@ public static MockOidcProvider start() {

/** A provider that shapes its issuer and claims the way {@code profile}'s real one does. */
public static MockOidcProvider start(OidcProviderProfile profile) {
MockOidcProvider provider = new MockOidcProvider(MockHttp.bindLoopbackServer(), profile);
return start(profile, false);
}

public static MockOidcProvider startPublicClient() {
return start(OidcProviderProfile.CUSTOM, true);
}

private static MockOidcProvider start(OidcProviderProfile profile, boolean publicClient) {
MockOidcProvider provider =
new MockOidcProvider(MockHttp.bindLoopbackServer(), profile, publicClient);
provider.server.start(provider.routes());
return provider;
}

public String clientId() {
return publicClient ? "om-sso-it-public-client" : CLIENT_ID;
}

public OidcProviderProfile profile() {
return profile;
}
Expand Down Expand Up @@ -130,6 +147,11 @@ public void defectNextIdToken(IdTokenDefect defect) {
tokens.defectNextIdToken(defect);
}

/** Models a provider registration which permits redemption only from a browser. */
public void registerRedirectForBrowserOnly() {
tokenEndpoint.registerRedirectForBrowserOnly();
}

public void answerRefreshesWith(RefreshOutcome outcome) {
tokenEndpoint.answerRefreshesWith(outcome);
}
Expand Down Expand Up @@ -245,6 +267,12 @@ private Map<String, String> authorizationResult(Map<String, String> query) {
if (refusal != null) {
return Map.of(ERROR, refusal);
}
if (publicClient
&& (!clientId().equals(query.get(MockOidcProtocol.CLIENT_ID))
|| !"S256".equals(query.get("code_challenge_method"))
|| query.getOrDefault(CODE_CHALLENGE, "").isBlank())) {
return Map.of(ERROR, "invalid_request");
}
MockOidcIdentity user = signedInUser.get();
return user == null ? Map.of(ERROR, LOGIN_REQUIRED) : Map.of(CODE, issueCode(user, query));
}
Expand Down Expand Up @@ -285,9 +313,11 @@ private Discovery discovery() {
List.of("code", "id_token", "code id_token"),
List.of("public"),
List.of("RS256"),
List.of(CLIENT_SECRET_BASIC, CLIENT_SECRET_POST),
publicClient ? List.of("none") : List.of(CLIENT_SECRET_BASIC, CLIENT_SECRET_POST),
List.of("S256"),
List.of(GRANT_AUTHORIZATION_CODE, GRANT_REFRESH_TOKEN, GRANT_CLIENT_CREDENTIALS),
publicClient
? List.of(GRANT_AUTHORIZATION_CODE)
: List.of(GRANT_AUTHORIZATION_CODE, GRANT_REFRESH_TOKEN, GRANT_CLIENT_CREDENTIALS),
mode.isAdvertised() ? Boolean.TRUE : null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ final class MockOidcTokenEndpoint implements HttpHandler {
private final MockRequestJournal journal;
private final String clientId;
private final String clientSecret;
private volatile boolean browserOnlyRedirect;
private final AtomicReference<RefreshOutcome> refreshOutcome =
new AtomicReference<>(RefreshOutcome.renew());
private final AtomicReference<RefreshOutcome> nextCodeExchangeFailure = new AtomicReference<>();
Expand All @@ -57,6 +58,10 @@ final class MockOidcTokenEndpoint implements HttpHandler {
this.clientSecret = clientSecret;
}

void registerRedirectForBrowserOnly() {
browserOnlyRedirect = true;
}

void answerRefreshesWith(RefreshOutcome outcome) {
refreshOutcome.set(outcome);
}
Expand Down Expand Up @@ -105,7 +110,9 @@ private void respondToGrant(HttpExchange exchange, Map<String, String> form) thr
private void respondToCodeExchange(HttpExchange exchange, Map<String, String> form)
throws IOException {
RefreshOutcome failure = nextCodeExchangeFailure.getAndSet(null);
if (failure == null) {
if (browserOnlyRedirect && exchange.getRequestHeaders().getFirst("Origin") == null) {
respondError(exchange, BAD_REQUEST, "invalid_request");
} else if (failure == null) {
respondWithTokens(exchange, redeemCode(form));
} else {
respondWith(exchange, failure);
Expand Down Expand Up @@ -152,6 +159,12 @@ private static void respondWith(HttpExchange exchange, RefreshOutcome outcome)

private boolean isRegisteredClient(HttpExchange exchange, Map<String, String> form) {
String authorization = exchange.getRequestHeaders().getFirst(MockHttp.AUTHORIZATION);
if (clientSecret == null) {
return authorization == null
&& !form.containsKey(CLIENT_SECRET)
&& clientId.equals(form.get(CLIENT_ID))
&& GRANT_AUTHORIZATION_CODE.equals(form.get(GRANT_TYPE));
}
String[] credentials =
authorization == null
? new String[] {form.get(CLIENT_ID), form.get(CLIENT_SECRET)}
Expand Down
Loading
Loading