-
Notifications
You must be signed in to change notification settings - Fork 16
Add sovereign cloud support to next/core (GCCH, DoD, China) #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
corinagum
wants to merge
10
commits into
next/core
Choose a base branch
from
cg/sovereign-cloud-nextcore
base: next/core
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
29d6075
Add sovereign cloud support (GCCH, DoD, China)
rajan-chari 477de27
Add individual cloud endpoint overrides to TeamsSettings
rajan-chari c8d87f2
Clean up PR: rename BotScope instance to ActiveBotScope, remove unrel…
corinagum bc733c4
Add sovereign cloud validation and ActiveBotScope tests
corinagum b026c00
Add sovereign cloud support to core/ package
corinagum 2727e7a
Merge next/core and update sovereign cloud support for refactored hos…
corinagum 5254a4b
Apply Graph Scope and fixes
corinagum 1b341dc
Add sovereign cloud support to JWT validation and MSAL section config
corinagum ef6d67d
Add CloudEnvironment and add STS endpoint and tests
corinagum caf3422
Fixes
corinagum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.Teams.Api.Auth; | ||
|
|
||
| /// <summary> | ||
| /// Bundles all cloud-specific service endpoints for a given Azure environment. | ||
| /// Use predefined instances (<see cref="Public"/>, <see cref="USGov"/>, <see cref="USGovDoD"/>, <see cref="China"/>) | ||
| /// or construct a custom one. | ||
| /// </summary> | ||
| public class CloudEnvironment | ||
| { | ||
| /// <summary> | ||
| /// The Azure AD login endpoint (e.g. "https://login.microsoftonline.com"). | ||
| /// </summary> | ||
| public string LoginEndpoint { get; } | ||
|
|
||
| /// <summary> | ||
| /// The default multi-tenant login tenant (e.g. "botframework.com"). | ||
| /// </summary> | ||
| public string LoginTenant { get; } | ||
|
|
||
| /// <summary> | ||
| /// The Bot Framework OAuth scope (e.g. "https://api.botframework.com/.default"). | ||
| /// </summary> | ||
| public string BotScope { get; } | ||
|
|
||
| /// <summary> | ||
| /// The Bot Framework token service base URL (e.g. "https://token.botframework.com"). | ||
| /// </summary> | ||
| public string TokenServiceUrl { get; } | ||
|
|
||
| /// <summary> | ||
| /// The OpenID metadata URL for token validation (e.g. "https://login.botframework.com/v1/.well-known/openidconfiguration"). | ||
| /// </summary> | ||
| public string OpenIdMetadataUrl { get; } | ||
|
|
||
| /// <summary> | ||
| /// The token issuer for Bot Framework tokens (e.g. "https://api.botframework.com"). | ||
| /// </summary> | ||
| public string TokenIssuer { get; } | ||
|
|
||
| /// <summary> | ||
| /// The channel service URL. Empty for public cloud; set for sovereign clouds | ||
| /// (e.g. "https://botframework.azure.us"). | ||
| /// </summary> | ||
| public string ChannelService { get; } | ||
|
|
||
| /// <summary> | ||
| /// The OAuth redirect URL (e.g. "https://token.botframework.com/.auth/web/redirect"). | ||
| /// </summary> | ||
| public string OAuthRedirectUrl { get; } | ||
|
|
||
| /// <summary> | ||
| /// The Microsoft Graph token scope (e.g. "https://graph.microsoft.com/.default"). | ||
| /// </summary> | ||
| public string GraphScope { get; } | ||
|
|
||
| public CloudEnvironment( | ||
| string loginEndpoint, | ||
| string loginTenant, | ||
| string botScope, | ||
| string tokenServiceUrl, | ||
| string openIdMetadataUrl, | ||
| string tokenIssuer, | ||
| string channelService, | ||
| string oauthRedirectUrl, | ||
| string graphScope = "https://graph.microsoft.com/.default") | ||
| { | ||
| LoginEndpoint = loginEndpoint; | ||
| LoginTenant = loginTenant; | ||
| BotScope = botScope; | ||
| TokenServiceUrl = tokenServiceUrl; | ||
| OpenIdMetadataUrl = openIdMetadataUrl; | ||
| TokenIssuer = tokenIssuer; | ||
| ChannelService = channelService; | ||
| OAuthRedirectUrl = oauthRedirectUrl; | ||
| GraphScope = graphScope; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Microsoft public (commercial) cloud. | ||
| /// </summary> | ||
| public static readonly CloudEnvironment Public = new( | ||
| loginEndpoint: "https://login.microsoftonline.com", | ||
| loginTenant: "botframework.com", | ||
| botScope: "https://api.botframework.com/.default", | ||
| tokenServiceUrl: "https://token.botframework.com", | ||
| openIdMetadataUrl: "https://login.botframework.com/v1/.well-known/openidconfiguration", | ||
| tokenIssuer: "https://api.botframework.com", | ||
| channelService: "", | ||
| oauthRedirectUrl: "https://token.botframework.com/.auth/web/redirect", | ||
| graphScope: "https://graph.microsoft.com/.default" | ||
| ); | ||
|
|
||
| /// <summary> | ||
| /// US Government Community Cloud High (GCCH). | ||
| /// </summary> | ||
| public static readonly CloudEnvironment USGov = new( | ||
| loginEndpoint: "https://login.microsoftonline.us", | ||
| loginTenant: "MicrosoftServices.onmicrosoft.us", | ||
| botScope: "https://api.botframework.us/.default", | ||
| tokenServiceUrl: "https://tokengcch.botframework.azure.us", | ||
| openIdMetadataUrl: "https://login.botframework.azure.us/v1/.well-known/openidconfiguration", | ||
| tokenIssuer: "https://api.botframework.us", | ||
| channelService: "https://botframework.azure.us", | ||
| oauthRedirectUrl: "https://tokengcch.botframework.azure.us/.auth/web/redirect", | ||
| graphScope: "https://graph.microsoft.us/.default" | ||
| ); | ||
|
|
||
| /// <summary> | ||
| /// US Government Department of Defense (DoD). | ||
| /// </summary> | ||
| public static readonly CloudEnvironment USGovDoD = new( | ||
| loginEndpoint: "https://login.microsoftonline.us", | ||
| loginTenant: "MicrosoftServices.onmicrosoft.us", | ||
| botScope: "https://api.botframework.us/.default", | ||
| tokenServiceUrl: "https://apiDoD.botframework.azure.us", | ||
| openIdMetadataUrl: "https://login.botframework.azure.us/v1/.well-known/openidconfiguration", | ||
| tokenIssuer: "https://api.botframework.us", | ||
| channelService: "https://botframework.azure.us", | ||
| oauthRedirectUrl: "https://apiDoD.botframework.azure.us/.auth/web/redirect", | ||
| graphScope: "https://dod-graph.microsoft.us/.default" | ||
| ); | ||
|
|
||
| /// <summary> | ||
| /// China cloud (21Vianet). | ||
| /// </summary> | ||
| public static readonly CloudEnvironment China = new( | ||
| loginEndpoint: "https://login.partner.microsoftonline.cn", | ||
| loginTenant: "microsoftservices.partner.onmschina.cn", | ||
| botScope: "https://api.botframework.azure.cn/.default", | ||
| tokenServiceUrl: "https://token.botframework.azure.cn", | ||
| openIdMetadataUrl: "https://login.botframework.azure.cn/v1/.well-known/openidconfiguration", | ||
| tokenIssuer: "https://api.botframework.azure.cn", | ||
| channelService: "https://botframework.azure.cn", | ||
| oauthRedirectUrl: "https://token.botframework.azure.cn/.auth/web/redirect", | ||
| graphScope: "https://microsoftgraph.chinacloudapi.cn/.default" | ||
| ); | ||
|
|
||
| /// <summary> | ||
| /// Creates a new <see cref="CloudEnvironment"/> by applying non-null overrides on top of this instance. | ||
| /// Returns the same instance if all overrides are null (no allocation). | ||
| /// </summary> | ||
| public CloudEnvironment WithOverrides( | ||
| string? loginEndpoint = null, | ||
| string? loginTenant = null, | ||
| string? botScope = null, | ||
| string? tokenServiceUrl = null, | ||
| string? openIdMetadataUrl = null, | ||
| string? tokenIssuer = null, | ||
| string? channelService = null, | ||
| string? oauthRedirectUrl = null, | ||
| string? graphScope = null) | ||
| { | ||
| // Normalize empty/whitespace to null so blank config values don't override valid defaults | ||
| loginEndpoint = NullIfWhiteSpace(loginEndpoint); | ||
| loginTenant = NullIfWhiteSpace(loginTenant); | ||
| botScope = NullIfWhiteSpace(botScope); | ||
| tokenServiceUrl = NullIfWhiteSpace(tokenServiceUrl); | ||
| openIdMetadataUrl = NullIfWhiteSpace(openIdMetadataUrl); | ||
| tokenIssuer = NullIfWhiteSpace(tokenIssuer); | ||
| channelService = NullIfWhiteSpace(channelService); | ||
| oauthRedirectUrl = NullIfWhiteSpace(oauthRedirectUrl); | ||
| graphScope = NullIfWhiteSpace(graphScope); | ||
|
|
||
| if (loginEndpoint is null && loginTenant is null && botScope is null && | ||
| tokenServiceUrl is null && openIdMetadataUrl is null && tokenIssuer is null && | ||
| channelService is null && oauthRedirectUrl is null && graphScope is null) | ||
| { | ||
| return this; | ||
| } | ||
|
|
||
| return new CloudEnvironment( | ||
| loginEndpoint ?? LoginEndpoint, | ||
| loginTenant ?? LoginTenant, | ||
| botScope ?? BotScope, | ||
| tokenServiceUrl ?? TokenServiceUrl, | ||
| openIdMetadataUrl ?? OpenIdMetadataUrl, | ||
| tokenIssuer ?? TokenIssuer, | ||
| channelService ?? ChannelService, | ||
| oauthRedirectUrl ?? OAuthRedirectUrl, | ||
| graphScope ?? GraphScope | ||
| ); | ||
| } | ||
|
|
||
| private static string? NullIfWhiteSpace(string? value) => | ||
| string.IsNullOrWhiteSpace(value) ? null : value; | ||
|
|
||
| /// <summary> | ||
| /// Resolves a cloud environment name (case-insensitive) to its corresponding instance. | ||
| /// Valid names: "Public", "USGov", "USGovDoD", "China". | ||
| /// </summary> | ||
| public static CloudEnvironment FromName(string name) => name.ToLowerInvariant() switch | ||
| { | ||
| "public" => Public, | ||
| "usgov" => USGov, | ||
| "usgovdod" => USGovDoD, | ||
| "china" => China, | ||
| _ => throw new ArgumentException($"Unknown cloud environment: '{name}'. Valid values are: Public, USGov, USGovDoD, China.", nameof(name)) | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.