diff --git a/src/Common/Constants.ts b/src/Common/Constants.ts index cde5e9462..ce0042890 100644 --- a/src/Common/Constants.ts +++ b/src/Common/Constants.ts @@ -183,6 +183,12 @@ export class CassandraProxyAPIs { public static readonly connectionStringSchemaApi: string = "api/connectionstring/cassandra/schema"; } +export class AadEndpoints { + public static readonly Prod: string = "https://login.microsoftonline.com/"; + public static readonly Fairfax: string = "https://login.microsoftonline.us/"; + public static readonly Mooncake: string = "https://login.partner.microsoftonline.cn/"; +} + export class Queries { public static CustomPageOption: string = "custom"; public static UnlimitedPageOption: string = "unlimited"; diff --git a/src/ConfigContext.ts b/src/ConfigContext.ts index 8db033788..49cd6fb60 100644 --- a/src/ConfigContext.ts +++ b/src/ConfigContext.ts @@ -5,6 +5,7 @@ import { MongoProxyEndpoints, PortalBackendEndpoints, } from "Common/Constants"; +import { userContext } from "UserContext"; import { allowedAadEndpoints, allowedArcadiaEndpoints, @@ -36,6 +37,7 @@ export interface ConfigContext { gitSha?: string; proxyPath?: string; AAD_ENDPOINT: string; + ENVIRONMENT: string; ARM_AUTH_AREA: string; ARM_ENDPOINT: string; EMULATOR_ENDPOINT?: string; @@ -91,7 +93,7 @@ let configContext: Readonly = { ], // Webpack injects this at build time gitSha: process.env.GIT_SHA, hostedExplorerURL: "https://cosmos.azure.com/", - AAD_ENDPOINT: "https://login.microsoftonline.com/", + AAD_ENDPOINT: "", ARM_AUTH_AREA: "https://management.azure.com/", ARM_ENDPOINT: "https://management.azure.com/", ARM_API_VERSION: "2016-06-01", diff --git a/src/Utils/EndpointUtils.ts b/src/Utils/EndpointUtils.ts index b685dc71a..fb505a431 100644 --- a/src/Utils/EndpointUtils.ts +++ b/src/Utils/EndpointUtils.ts @@ -52,7 +52,10 @@ export const defaultAllowedArmEndpoints: ReadonlyArray = [ "https://management.chinacloudapi.cn", ]; -export const allowedAadEndpoints: ReadonlyArray = ["https://login.microsoftonline.com/"]; +export const allowedAadEndpoints: ReadonlyArray = ["https://login.microsoftonline.com/", + "https://login.microsoftonline.us/", + "https://login.partner.microsoftonline.cn/" +]; export const defaultAllowedBackendEndpoints: ReadonlyArray = [ "https://main.documentdb.ext.azure.com", diff --git a/src/hooks/useKnockoutExplorer.ts b/src/hooks/useKnockoutExplorer.ts index fcf1d314e..ae0b36988 100644 --- a/src/hooks/useKnockoutExplorer.ts +++ b/src/hooks/useKnockoutExplorer.ts @@ -4,6 +4,7 @@ import { DATA_EXPLORER_RPC_VERSION } from "Contracts/DataExplorerMessagesContrac import { FabricMessageTypes } from "Contracts/FabricMessageTypes"; import { FABRIC_RPC_VERSION, FabricMessageV2 } from "Contracts/FabricMessagesContract"; import Explorer from "Explorer/Explorer"; +import { useDataPlaneRbac } from "Explorer/Panes/SettingsPane/SettingsPane"; import { useSelectedNode } from "Explorer/useSelectedNode"; import { scheduleRefreshDatabaseResourceToken } from "Platform/Fabric/FabricUtil"; import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility"; @@ -15,6 +16,7 @@ import { useEffect, useState } from "react"; import { AuthType } from "../AuthType"; import { AccountKind, Flights } from "../Common/Constants"; import { normalizeArmEndpoint } from "../Common/EnvironmentUtility"; +import * as Logger from "../Common/Logger"; import { handleCachedDataMessage, sendMessage, sendReadyMessage } from "../Common/MessageHandler"; import { Platform, configContext, updateConfigContext } from "../ConfigContext"; import { ActionType, DataExplorerAction, TabKind } from "../Contracts/ActionContracts"; @@ -42,8 +44,6 @@ import { acquireTokenWithMsal, getAuthorizationHeader, getMsalInstance } from ". import { isInvalidParentFrameOrigin, shouldProcessMessage } from "../Utils/MessageValidation"; import { getReadOnlyKeys, listKeys } from "../Utils/arm/generatedClients/cosmos/databaseAccounts"; import { applyExplorerBindings } from "../applyExplorerBindings"; -import { useDataPlaneRbac } from "Explorer/Panes/SettingsPane/SettingsPane"; -import * as Logger from "../Common/Logger"; // This hook will create a new instance of Explorer.ts and bind it to the DOM // This hook has a LOT of magic, but ideally we can delete it once we have removed KO and switched entirely to React @@ -642,6 +642,31 @@ function updateContextsFromPortalMessage(inputs: DataExplorerInputsFrame) { PORTAL_BACKEND_ENDPOINT: inputs.portalBackendEndpoint, }); + const portalEnv = inputs.serverId as PortalEnv; + + switch (portalEnv) { + case "prod1": + case "prod": + updateConfigContext({ + AAD_ENDPOINT: Constants.AadEndpoints.Prod + }); + break; + case "fairfax": + updateConfigContext({ + AAD_ENDPOINT: Constants.AadEndpoints.Fairfax + }); + break; + case "mooncake": + updateConfigContext({ + AAD_ENDPOINT: Constants.AadEndpoints.Mooncake + }); + break; + + default: + console.warn(`Unknown portal environment: ${portalEnv}`); + break; + } + updateUserContext({ authorizationToken, databaseAccount,