Microsoft Teams App SSO
Microsoft Teams App SSO
Implemented in version: 0.242.072
Overview
SimpleChat can run as a Microsoft Teams personal tab and authenticate users with Teams Single Sign-On (SSO). The feature uses the Teams JavaScript SDK in the browser and the Microsoft identity On-Behalf-Of (OBO) flow on the Flask backend.
This feature requires both a Teams app package and SimpleChat runtime configuration. The Teams package tells Teams what tab URL and Entra Application ID URI to use. The SimpleChat runtime flag enables Teams frame support, token exchange, secure cross-site session cookies, and app-level authentication handling.
Dependencies
- Microsoft Teams app manifest with
webApplicationInfoconfigured. - Entra app registration with an exposed API scope such as
access_as_user. ENABLE_TEAMS_SSO=trueor the deployerenableTeamsSso=trueparameter.- Local Teams JavaScript SDK asset at
application/single_app/static/js/MicrosoftTeams.min.js.
Technical Specifications
Backend
/login?teams=truerenders the Teams-aware login bootstrap page./auth/teams/token-exchangeaccepts the Teams SSO assertion, exchanges it through MSAL OBO, and creates the Flask session.- The token exchange endpoint is feature-gated by
ENABLE_TEAMS_SSO. - The global same-origin guard also protects the pre-session Teams token exchange POST.
- Session user data is populated from OBO ID token claims, the validated Teams assertion claims, and Microsoft Graph
/mefallback data.
Security Headers And Cookies
- When Teams SSO is disabled,
X-Frame-Options: DENYremains active. - When Teams SSO is enabled, CSP
frame-ancestorsincludes configured Teams origins andX-Frame-Optionsis omitted. - Teams SSO forces
SESSION_COOKIE_SAMESITE=NoneandSESSION_COOKIE_SECURE=true. - Commercial and Azure Government defaults are provided; custom clouds can set explicit Teams origins.
Deployment
deployers/bicep/main.bicepexposesenableTeamsSso,teamsFrameAncestors,customTeamsOrigins, andteamsAppResource.deployers/bicep/modules/appService.bicepsets the corresponding app settings and lets unauthenticated requests reach the app-level login flow when Teams SSO is enabled.deployers/version.txtwas updated with the deployer patch version.
Usage Instructions
- Configure the Entra app registration Expose an API section.
- Set the Application ID URI and
access_as_userdelegated scope. - Preauthorize Teams client applications for that scope.
- Deploy SimpleChat with
enableTeamsSso=trueandteamsAppResourceset to the Application ID URI. - Build a Teams package from
application/teams_app/manifest.template.json,color.png, andoutline.png. - Upload or publish the Teams package.
- Open the SimpleChat tab in Teams.
See docs/how-to/teams_app.md for operator steps.
Testing And Validation
- Functional tests cover Teams configuration, security header behavior, token-exchange request validation, and session user construction.
- UI tests cover login template structure, local SDK loading, configured Teams resource usage, and fallback behavior.
- Python syntax checks and template-focused checks validate the changed runtime files.
Known Limitations
- The deployer does not publish the Teams app package; Teams app upload remains an administrator or developer action.
- Custom or air-gapped Teams clouds must provide explicit frame ancestors, SDK origins, and Application ID URI values.
- Teams SSO requires HTTPS because browsers require
Securecookies whenSameSite=Noneis used.