Skip to content

Sign in to embedded apps with a host token - #222

Merged
tnkuehne merged 3 commits into
mainfrom
feat/embedded-app-sign-in
Nov 19, 2026
Merged

tnkuehne merged 3 commits into
mainfrom
feat/embedded-app-sign-in

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Organizations want to show published apps inside pages their colleagues already use, such as a Microsoft Teams tab or a company portal. Today an app cannot be framed by another site, and company sign-in does not work in a frame:

  • App responses send frame-ancestors 'self'.
  • Identity providers refuse to render their sign-in pages in frames.
  • The app session cookie is SameSite=Lax, so a cross-site frame never sends it.

Changes

Settings. Organizations list the page origins that may embed their apps (embeddingOrigins, HTTPS origins with optional *. subdomain wildcard). This works through the settings UI (new Embedded apps section for Entra connections) and the existing settings API and CLI export/apply. An input that omits the field keeps the saved list, so older settings files do not clear it. The list is published with the app sign-in configuration only for Entra app identity, and removing SSO clears it.

Frame ancestors. The auth proxy passes the organization's list to the runtime, which adds it to each app response's frame-ancestors. App code cannot change it.

Embedded sign-in. A framed HTML navigation without a session (Sec-Fetch-Dest: iframe) goes to /oauth2/ORG/embedded on the auth host instead of the provider:

  1. The page asks its parent for a host token (widefleet:host-token-request) and accepts the answer only from a configured origin. Tokens are exchanged with the auth host only, never with the app frame.
  2. The proxy verifies the token as an Entra v2 delegated access token for the organization's app sign-in client and tenant. Its audience is the same client that signs users in to apps, so it proves the same identity as a regular sign-in.
  3. It resolves groups with an on-behalf-of Microsoft Graph token, reusing the existing nested group lookup. Apps receive the same user ID (oid), and app access rules apply unchanged.
  4. It issues a separate HttpOnly; Secure; SameSite=None; Partitioned session cookie that expires with the host token. The cookie exists only under the embedding top-level site and holds no refresh credential. After expiry, the next framed navigation asks the host again, so access is rechecked with every new token.
  5. Before returning to the app, the page confirms that the browser kept the session. If it did not, the page offers to open the app in a new tab instead of looping.

Sign-out also clears the embedded session. docs/architecture.md records the boundary.

Screens

Settings and the embedded sign-in page with synthetic fixtures, rendered from the merge base (4dbf4aa0) and from this branch at 1280 and 390 px.

Company sign-in settings

Before, the page has no embedding section. After, Entra connections show Embedded apps below the email domains, and the removal text mentions embedding hosts.

Before After
light, 1280 px Before, light, 1280 px After, light, 1280 px
light, 390 px Before, light, 390 px After, light, 390 px
dark, 1280 px Before, dark, 1280 px After, dark, 1280 px
dark, 390 px Before, dark, 390 px After, dark, 390 px

Embedding hosts

A saved host, and the Add host dialog rejecting an HTTP origin.

Saved host Invalid origin
light, 1280 px Saved host, light, 1280 px Invalid origin, light, 1280 px
light, 390 px Saved host, light, 390 px Invalid origin, light, 390 px
dark, 1280 px Saved host, dark, 1280 px Invalid origin, dark, 1280 px
dark, 390 px Saved host, dark, 390 px Invalid origin, dark, 390 px

Embedded sign-in page (new)

Shown in a frame of https://portal.example.test: waiting for the host, the host reporting that it has no token, and missing admin consent.

Signing in No host token Consent required
light, 1280 px Signing in, light, 1280 px No host token, light, 1280 px Consent required, light, 1280 px
light, 390 px Signing in, light, 390 px No host token, light, 390 px Consent required, light, 390 px
dark, 1280 px Signing in, dark, 1280 px No host token, dark, 1280 px Consent required, dark, 1280 px
dark, 390 px Signing in, dark, 390 px No host token, dark, 390 px Consent required, dark, 390 px

Not shown: the 15-second timeout and the server-error state, which use the same layout as "No host token" with the generic message.

Verification

  • pnpm check, full pnpm exec vitest run against the local test services (1101 passed), and the self-hosted SSO Playwright spec.
  • New proxy tests cover redirects for framed and top-level navigations, rejection of unregistered destinations and organizations without embedding, the token exchange, cookie attributes, forwarded identity, app access rules, expiry, and rejection of tokens for another client, another tenant, app-only or v1 tokens. They also cover the Origin and content-type checks, consent and outage errors, and sign-out.
  • A Chromium test (RUN_EDGE_TESTS=1) embeds an app from a cross-site page that answers the token request. It checks the forwarded identity and the cookie's partition key, and that a page on an unlisted site gets no app. Without Partitioned the test fails.
  • Settings integration test for publishing, preserving and clearing the list. The e2e spec adds and removes a host in the UI and validates input. I checked the screenshots at 1280 and 390 px in light and dark: the section matches Email domains, the page does not scroll horizontally, and focus returns to Add host after the dialog.

Not verified here: a real Teams client, and Safari. Safari supports partitioned cookies from 26.2. Playwright's Linux WebKit does not implement cookie partitions, so it cannot test this flow.

Documentation: #223 (draft, blocked on the release that contains this change).

RetriggerView in GreptileConfidence Score: 3/5 Tier: plus

Do not merge until host changes cannot overwrite connection saves and older settings files can remove SSO.

Findings

  1. P1 Host edits undo connection saves ▶
  2. P1 Older settings cannot remove SSO. ▶

Summary

Adds host-token sign-in for Entra apps embedded on approved sites, with separate cookies that expire with the host token.

  • Organizations can choose which pages may show their Entra apps.
  • Framed app visits can sign in with a token from their host.

A host change can overwrite a connection save that is still running.

Diagram

sequenceDiagram
    participant Host as Approved host page
    participant Page as Auth-host frame
    participant Proxy as Auth proxy
    participant Entra as Entra and Graph
    participant App as App runtime
    Page->>Host: Request host token
    Host->>Page: Return token
    Page->>Proxy: Submit token on auth host
    Proxy->>Entra: Verify token and fetch user and groups
    Proxy-->>Page: Set partitioned session cookie
    Page->>Proxy: Confirm cookie was kept
    Page->>Proxy: Navigate back to app
    Proxy->>Proxy: Check session and app access
    Proxy->>App: Forward identity, without sign-in cookies
    App-->>Page: App response with approved frame hosts
Loading

Reviews (9) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile

Pages such as a Microsoft Teams tab can now show published apps in a
frame. The provider's sign-in page refuses to render in frames and the
regular Lax session cookie is not sent there, so a framed navigation
without a session goes to a sign-in page on the auth host instead. That
page asks its embedding page for a host token through postMessage, and
the proxy verifies it against the organization's Entra client and
tenant, resolves groups through on-behalf-of Graph access and issues a
partitioned session that expires with the token.

Organizations list the hosts that may embed their apps in their
settings. The list becomes the apps' frame-ancestors and is published
only for Entra app identity.
Comment thread packages/auth-proxy/src/proxy.ts Resolved
Comment thread packages/auth-proxy/src/embedded.ts Resolved
Comment thread packages/auth-proxy/src/embedded.ts Resolved
Comment thread packages/contracts/src/settings.ts Resolved
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs d3e958d Nov 19 2026, 09:22 AM

The auth worker selected organizations on the auth host only for the
regular OAuth paths, so the embedded sign-in page and its session check
returned 404 in deployments.

Embedded sessions now span numbered cookies like regular sessions, so
identities with many groups stay within the browser's per-cookie limit,
and a new sign-in expires leftover chunks. Accounts without a mailbox
use their sign-in name as email. Embedding origins drop the default
HTTPS port, which browsers omit from message origins. The connection
form no longer carries the embedding hosts, so saving it cannot restore
a host removed meanwhile.
…ign-in

# Conflicts:
#	apps/control-plane/src/lib/server/app-sign-in-installed.ts
#	packages/auth-proxy/src/configuration.ts
#	packages/auth-proxy/src/worker.test.ts
@tnkuehne
tnkuehne merged commit dc24ba1 into main Nov 19, 2026
16 checks passed
@tnkuehne
tnkuehne deleted the feat/embedded-app-sign-in branch November 19, 2026 09:32
Comment on lines +354 to +358
const embedding =
next.embeddingOrigins ??
(await readOrganizationSettings(database, organizationId)).embeddingOrigins;

if (embedding.length && next.sso?.appIdentityType !== "entra")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Older settings cannot remove SSO. After embedding hosts are saved, applying an older settings file with sso: null and directory: null fails here. The omitted embeddingOrigins becomes the saved nonempty list, which is then rejected because next.sso is null. This blocks an existing API/CLI removal request instead of clearing the hosts as the UI does. Clear the hosts when SSO is removed, while preserving omitted lists for Entra updates.

Comment on lines +40 to +43
const save = async (next: string[]) => {
await writer.save(() =>
ssoInput({ ...ssoDraft(view, organizationId), embeddingOrigins: next }, view),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Host edits undo connection saves. The host buttons stay enabled while the connection form saves. This call copies the full sso from the still-old view, so a host change sent during that save can run second and restore the old connection settings. A client and secret rotation can then leave sign-in broken. Save hosts without resending the connection, or block host changes until the connection save and refresh finish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant