When a hosted agent reaches an MCP tool through a Microsoft Foundry Toolbox with OAuth identity passthrough, the first call for each user and connection needs consent. Foundry does not ask for it inside the conversation. It returns a consent link, and the user approves access in a separate browser window.
The Foundry portal handles that window for you. A custom chat has to handle it itself. In a React client that already treats an unfinished response as a failure, a consent challenge looks like a broken turn: the stream ends early, no continuation is issued, and the thread locks.
This article follows the challenge from the hosted agent, through an application-owned Backend for Frontend (BFF), into a React chat. It covers how the client recognizes the challenge, why the paused turn must not be treated as failed, how the popup and a single resend work, and two defects that the hosted runs exposed.
How an
oauth_consent_requestitem reaches the browser and ends the turn asresponse.incomplete.Why the client keeps the thread usable and discards the stored continuation.
How a registered popup and a guarded, single resend continue the request.
What the hosted runs showed, and what remains unproven.
Starting point
The implementation extends Microsoft's public banking-assistant sample. The BFF, the Identity service that acts as the OAuth authorization server, the Toolbox wiring, the consent middleware and the React chat are this repository's additions.
Three earlier articles cover the neighboring pieces. Compare direct MCP and Microsoft Foundry Toolbox in Microsoft Agent Framework explains why the hosted path uses one Toolbox per connection and how Agent Framework middleware turns discovery-time and call-time consent into native oauth_consent_request content. Bind Microsoft Foundry agent conversations to authenticated users with a BFF explains the signed continuation token that the BFF issues only after a completed response. Build a Streaming React Chat with Microsoft Foundry Responses covers SSE parsing and stale-output suppression. This article starts where the first one ends and builds on the other two.
Snippets are reduced excerpts, not a runnable application.
What the browser receives
Foundry's OAuth identity passthrough guidance states the contract: the consent link arrives in response.output_item as an item of type oauth_consent_request, under consent_link. The client should present it as a link or button that opens the authorization flow in a browser window. Consent is scoped per connection, per user and per Foundry project.
In this application, the Foundry Responses host ends the turn with response.incomplete after emitting that item. The agent's consent middleware tests assert that shape: status incomplete, never failed, with the link in an oauth_consent_request output item.
The BFF forwards the stream unchanged, but it does not issue a continuation for this turn. Its continuation stream signs a continuation token only after response.completed. Any error, response.failed or response.incomplete event makes it append a controlled error instead:
data: {"type":"error","code":"CONTINUATION_UNAVAILABLE","allow_retry":false}The BFF does not know whether the turn paused for consent or broke. Keeping that rule unconditional is deliberate: the BFF never issues a continuation for a turn that did not complete. Interpreting the pause is the client's job.

Figure 1. The consent journey in this application. The BFF ends the paused turn without a continuation; the client recognizes the pause, opens the popup and resends once. Implementation schematic, not a runtime trace.
Recognize the challenge before the turn ends
The chat provider sets a per-turn flag when it sees the consent item. The order matters: the item always arrives before response.incomplete and the BFF error, so the flag is already set when the end-of-turn events come in.
// Simplified excerpt from ResponsesChatProvider.tsx
if (event.type === "response.incomplete" && !consentRequestedRef.current) {
markTurnFailed(threadId); // simplified: an ordinary incomplete turn still fails
}
if (consentRequestedRef.current &&
(event.type === "response.incomplete" || event.code === "CONTINUATION_UNAVAILABLE")) {
return; // a consent pause, not a failure
}
if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
const item = event.item;
if (item?.type === "oauth_consent_request") {
const link = typeof item.consent_link === "string" ? item.consent_link : "";
if (!link.startsWith("https://")) return;
consentRequestedRef.current = true;
consentThreadRef.current = threadId;
registerConsentLink(link);
addConsentCard(threadId, `consent_${threadId}_${link}`, link); // simplified
return;
}
}Three details carry most of the behavior:
The flag only reinterprets end-of-turn events. An
incompleteturn without a consent item keeps its existing failure path, and the thread locks as before.The card identifier derives from the link, so the
addedanddoneevents for the same item produce one card. When several connections need consent in the same turn, each link gets its own card.Only HTTPS links are shown. The link is rendered for the customer and never sent back to the model.
Keep the thread usable, but drop the continuation
When the stream finishes, the provider classifies the turn. A consent pause ends before any tool ran, so the provider leaves the thread unlocked. This is a narrow exception to the application's recovery rule: interrupted or uncertain turns lock the thread and are never resent automatically, because they may have started a business action.
The pause does change one piece of state. The paused turn advanced the agent's workflow, so the continuation stored from the previous completed turn no longer matches the server side. Reusing it on the next request would ask the host to continue from a state that has moved on. The provider removes it:
// Simplified excerpt from ResponsesChatProvider.tsx
const consentPause = consentRequestedRef.current && !streamFailedRef.current;
if (outcome === "success" || consentPause) {
recoveryBlockedRef.current.delete(threadId);
if (consentPause) continuationsRef.current.delete(threadId);
}The tradeoff is visible to the user. The messages remain on screen, but the next request starts a new provider conversation without earlier server-side context. For a single question interrupted by consent, that is acceptable. For a long conversation, the agent may need the customer to restate details.
Open a popup and resend once
The Markdown renderer opens a link in a popup only when the link was registered as a consent challenge. Any other link keeps its normal navigation:
// consentPopup.ts (reduced)
export function openConsentPopup(href: string | undefined): boolean {
if (!href || !consentLinks.has(href)) return false;
const popup = window.open(href, "banking-consent", "popup,width=520,height=720");
if (!popup) return false;
window.clearInterval(watchTimer);
watchTimer = window.setInterval(() => {
if (!popup.closed) return;
window.clearInterval(watchTimer);
closedHandler?.();
}, 500);
return true;
}The consent page belongs to another origin, so the chat cannot read its result. Foundry's guidance describes a confirmation page that tells the user to close the window; the popup closing is the only completion signal the client can observe. The popup module therefore polls popup.closed every 500 ms. The named window is reused, so only the latest popup is watched.
When it closes, the provider resends the paused message once. The resend is guarded: it runs only if the same thread is still active, the original message is known and no other stream is running. It repeats the input without adding a second user message to the chat. A consent requested during a widget action, such as a dispute decision, is not resent, because there is no chat message to repeat.
The resend is safe for one reason: the paused turn ran no business action. Closing the popup does not prove consent was granted. If the user denies access and closes the window, the resend should produce another challenge, but that path has not been verified in a browser yet.
Two defects the hosted runs exposed
A resend that disappeared
In early hosted runs, consent sometimes completed and the popup closed, but no request reached the BFF until the user typed again.
Closing the popup refocuses the chat window. The OAuth readiness provider starts a read-only status check on focus. The resend calls verify() before dispatching, and verify() rejected concurrent calls by returning false. When the focus check was still in flight, the resend was dropped silently. Which check finished first decided the outcome.
The fix shares the in-flight check instead of reporting not ready:
// Excerpt from OAuthReadinessContext.tsx
// A focus check may already be in flight when a caller needs the answer (for example the
// consent popup closing refocuses this window); share it instead of reporting not ready.
if (checking.current) return checking.current;
if (pending.current) return Promise.resolve(false);An authorization in progress still reports not ready. The general lesson is that a readiness gate returning false for "busy" is indistinguishable from "not authorized" to its caller.
A generic failure that hid the real error
The turn after a consent pause twice ended with response.failed and a message naming only the hosting phase: Native workflow execution failed. The BFF then emitted CONTINUATION_UNAVAILABLE and the thread locked, as it should for a real failure.
The cause was not in the consent path. Application Insights recorded a ChatClientException on the triage agent's model call: a model-router deployment returned HTTP 200 and then failed inside the stream, before any tool ran. Switching triage to a direct deployment removed the failure. The telemetry recorded neither the router's stream error code nor its selected model, so this is an observed incompatibility in two runs, not a general assessment of the router. The project's troubleshooting guide includes the query used to find it.
The lesson for consent work: when the turn after consent fails, inspect the agent's exceptions before changing the consent handling.
What the evidence supports
After the readiness fix, two customers used the hosted agent through the BFF and the React chat:
Each customer was asked separately for Account and Transaction consent, including the second customer after the first had already granted access.
Each popup close triggered one automatic resend.
After consent, each customer's tool results contained only their own name and accounts.
These observations show the journey works for two independently consented customers. They do not prove grant isolation. Denial of foreign resources, concurrent sessions, consent denial followed by closing the popup, grant expiry and logout remain unverified. The Agent Framework client also accepts any HTTPS consent host until an allowed-origins setting is configured.
Each resend starts a new hosted session, which adds container startup time to the first response after consent. It has not been measured systematically, so no latency figure is claimed here.
The offline regressions cover the pieces separately:
npm --prefix app\frontend\banking-web run test -- src\components\chat\ResponsesChatProvider.test.tsx src\components\chat\consentPopup.test.ts src\context\OAuthReadinessContext.test.tsx
uv run --directory app\responses-bff --no-sync python -m pytest tests\test_continuation.py -q
uv run --directory app\agent --no-sync python -m pytest tests\test_toolbox_consent_middleware.py tests\test_native_consent_boundary.py -qThese passed 127, 24 and 19 tests. They check the consent card, the unlocked thread, the discarded continuation, the single resend, non-HTTPS rejection, the shared readiness check, the BFF's refusal to issue a continuation for an incomplete turn and the host's incomplete status. They mock the browser and the platform, so they are not browser or hosted evidence.
Takeaways
Treat
oauth_consent_requestas a protocol challenge with its own UI. Recognize it before the end-of-turn events arrive, so anincompleteturn caused by consent is not handled as a failure.Keep the server rule simple: issue continuation only after
response.completed. Let the client decide what an incomplete turn means, and discard any continuation that the paused turn made stale.An automatic resend is safe only when the paused turn ran no business action. Keep it to one, gate it on the same thread and input, and never extend it to uncertain turns.
Before adopting this pattern, verify denial, expiry, logout and concurrent sessions in your own environment. Two successful customers are evidence of the journey, not of isolation.


Join the conversation! Your thoughts help the community grow.