Add sovereign cloud support (GCCH, DoD, China)#352
Conversation
- Add Startup section to CLAUDE.md with knowledge file loading, session context, private notes support, and quick-start commands - Add Lessons Learned section to CLAUDE.md for persistent knowledge - Create Claude-KB.md for cross-session learning - Add session-context.md and *-private.md to .gitignore Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Introduce CloudEnvironment class that bundles all cloud-specific service endpoints, with predefined instances for Public, USGov (GCCH), USGovDoD, and China (21Vianet). Thread the cloud environment through ClientCredentials, token clients, validation settings, and DI host builders so that all previously hardcoded endpoints are now configurable per cloud. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Manual Test ResultsTested locally by linking a scaffolded C# echo bot to this branch via Environment
Tests
ObservationThe config path ( Tested with teams-sdk-dev tooling. |
Allow users to override specific CloudEnvironment endpoints (e.g. LoginEndpoint, LoginTenant) via appsettings.json, enabling scenarios like China single-tenant bots that require a tenant-specific login URL. - Add CloudEnvironment.WithOverrides() for layering nullable overrides - Add 8 endpoint override properties + ResolveCloud() helper to TeamsSettings - Unify cloud resolution across Apply(), AddTeamsCore(), and AddTeamsTokenAuthentication() - Add WithOverrides unit tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Updated Test Results (after
|
| # | Test | Result |
|---|---|---|
| 1 | Invalid cloud name ("Cloud": "Narnia") |
Pass. Crashes with: Unknown cloud environment: 'Narnia'. Valid values are: Public, USGov, USGovDoD, China. |
| 2 | Default behavior (no Cloud key) | Pass. Bot starts, echoes messages. Defaults to CloudEnvironment.Public. |
| 3 | Named preset ("Cloud": "Public") |
Pass. Starts normally. |
| 4 | Single endpoint override ("TokenServiceUrl": "https://bogus.example.com/token") |
Pass. Bot starts (override accepted at startup, used at runtime). Proves individual override is wired through ResolveCloud → WithOverrides. |
| 5 | Preset + override ("Cloud": "USGov" + "LoginEndpoint": "https://custom-login.example.com") |
Pass. Bot starts with USGov as base and the custom LoginEndpoint applied on top. |
| 6 | Unit tests (CloudEnvironmentTests) |
Pass. All 21 tests pass, including 4 new WithOverrides tests (all-nulls, single, multiple, all overrides). |
Design Notes
WithOverridesreturnsthiswhen all overrides are null — nice zero-allocation fast path.ResolveCloudchains cleanly: programmaticAppOptions.Cloud→ config"Cloud"preset →Publicfallback → per-endpoint overrides. Priority order is clear.- All 8 endpoint properties are individually overridable from
appsettings.jsonunder theTeamssection.
URL Verification: CloudEnvironment presets vs Bot Framework docsCross-referenced all USGov (GCCH)
USGovDoD
Notes on the two
|
rido-min
left a comment
There was a problem hiding this comment.
Thank you for addressing sovereign cloud support - this is an important capability for government and regional customers.
I have some architectural concerns about the current approach that I'd like to discuss before we proceed:
- Hard-coded endpoint presets create a maintenance burden
The CloudEnvironment class embeds specific URLs for each sovereign cloud (GCCH, DoD, China). These endpoints have historically changed over time - when Microsoft updates them, this requires an SDK release
and forces all consumers to update their SDK version, even though their application logic hasn't changed. This couples deployment cycles unnecessarily.
The MSAL library itself avoids this pattern - it relies on well-known discovery documents (OpenID configuration endpoints) to resolve the actual service URLs at runtime. This approach is more resilient to
endpoint changes.
- Configuration-only approach is more flexible
Rather than providing presets, consider allowing sovereign cloud configuration entirely through settings:
{
"Teams": {
"LoginEndpoint": "https://login.microsoftonline.us",
"TokenServiceUrl": "https://tokengcch.botframework.azure.us",
...
}
}
This puts control in the hands of the deploying organization (who often have specific requirements in sovereign environments) rather than requiring SDK changes.
- Scattered client configuration
The current implementation adds TokenServiceUrl properties to individual clients (BotSignInClient, UserTokenClient, BotTokenClient). This means each client must be configured separately, which is error-prone
and harder to maintain than a centralized configuration that flows through to all clients.
Alternative approach to consider:
- Use the OpenID discovery document (already referenced as OpenIdMetadataUrl) to dynamically resolve endpoints where possible
- If presets are valuable for developer convenience, consider shipping them as a separate configuration file or NuGet package that can be updated independently of the core SDK
- Centralize cloud configuration in one place that all clients consume, rather than scattering it across multiple client classes
Would it be worth discussing these trade-offs before proceeding?
I dont think presets are valuable, we dont own the Entra URLs, and we should not hardcode those URLs in our codebase. @copilot what do you think about the comments in #352 (review) |
Summary
CloudEnvironmentclass (Microsoft.Teams.Api.Auth) bundling all cloud-specific service endpoints with predefined static instances:Public,USGov(GCCH),USGovDoD, andChina(21Vianet)ClientCredentials,BotTokenClient,UserTokenClient,BotSignInClient,App,TeamsValidationSettings, and DI host builders so all previously hardcoded endpoints are configurable per cloudCloudproperty toAppOptions(programmatic) andTeamsSettings(appsettings.json) for easy configurationTeamsSettings(e.g.LoginEndpoint,LoginTenant) for scenarios requiring per-endpoint customization — such as China single-tenant bots that need a tenant-specific login URLUsage
Named cloud preset (appsettings.json):
{ "Teams": { "ClientId": "...", "ClientSecret": "...", "Cloud": "USGov" } }Per-endpoint overrides (appsettings.json):
{ "Teams": { "ClientId": "...", "ClientSecret": "...", "TenantId": "your-tenant", "Cloud": "China", "LoginTenant": "your-tenant-id" } }Programmatic:
Valid cloud names:
Public(default),USGov,USGovDoD,ChinaOverride properties:
LoginEndpoint,LoginTenant,BotScope,TokenServiceUrl,OpenIdMetadataUrl,TokenIssuer,ChannelService,OAuthRedirectUrlFiles changed
Libraries/Microsoft.Teams.Api/Auth/CloudEnvironment.csTests/Microsoft.Teams.Api.Tests/Auth/CloudEnvironmentTests.csLibraries/Microsoft.Teams.Api/Auth/ClientCredentials.csLibraries/Microsoft.Teams.Api/Clients/BotTokenClient.csLibraries/Microsoft.Teams.Api/Clients/UserTokenClient.csLibraries/Microsoft.Teams.Api/Clients/BotSignInClient.csLibraries/Microsoft.Teams.Apps/AppOptions.csLibraries/Microsoft.Teams.Apps/App.csTeamsSettings.cs(Extensions.Configuration) — endpoint override properties +ResolveCloud()HostApplicationBuilder.cs(Extensions.Hosting) — unified cloud resolution viaResolveCloud()HostApplicationBuilder.cs(Plugins.AspNetCore) — unified cloud resolution viaResolveCloud()TeamsValidationSettings.cs(Plugins.AspNetCore)Test plan
dotnet build— 0 errorsdotnet test— all existing + new tests passCloudEnvironment.PublicURLs match current hardcoded values (backward compat)WithOverrides()with all nulls returns same instance (no allocation)CloudEnvironment.USGovURLs match BF GCCH docsCloudEnvironment.ChinaURLs match BF China docsSamples.Echo) starts correctly with no cloud config (defaults to Public)🤖 Generated with Claude Code