Skip to content

authentication.authenticate() fails when app is accessed through MCAS (Defender for Cloud Apps) proxy #3037

@nbelyh

Description

@nbelyh

When a Teams tab app is accessed through Microsoft Defender for Cloud Apps (MCAS) session proxy, authentication.authenticate() breaks because the popup and the opener end up on different origins, and notifySuccess()/notifyFailure() use postMessage which is blocked cross-origin.

How it happens
MCAS rewrites the app URL: app.example.com → app.example.com.mcas.ms

Tab (opener) is on https://app.example.com.mcas.ms
Popup opens auth-start on the same MCAS origin
auth-start redirects to Azure AD. The redirect_uri must use the real domain (app.example.com) because MCAS domains are dynamic and can't be pre-registered in Azure AD
Azure AD redirects back to https://app.example.com/auth-end — now on a different origin than the opener
notifySuccess() calls window.opener.postMessage() → blocked by browser (cross-origin)
Popup stays open, authenticate() never resolves

Expected behavior
authentication.authenticate() should handle the case where opener and popup are on different origins due to MCAS. This is a common enterprise scenario since MCAS is a Microsoft product used with Microsoft 365 tenants.

Environment
@microsoft/teams-js: 2.x
Teams client: Web browser, desktop
MCAS session policy active

Reproduction
Configure an MCAS session policy that proxies a Teams tab app
Open the tab in Teams web while MCAS is active
Trigger a consent flow via authentication.authenticate()
Popup completes Azure AD consent but never closes; authenticate() never resolves

What can you suggest? Is it possible to do authentication with MCAS enabled (having just the id token is not enough for our app)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions