From 44d6f29eddb296134f39804fcc9718012c77b567 Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Fri, 6 Oct 2023 14:35:30 +0000 Subject: [PATCH] Revert "For Fabric, send message to get Authorization token from iframe parent" This reverts commit 9db06af5520f0191569c4c68652171c49f218060. --- src/Common/CosmosClient.ts | 19 ++++------ src/Common/MessageHandler.ts | 2 +- src/Contracts/ExplorerContracts.ts | 43 +++++++++++++++++++++-- src/Contracts/FabricContract.ts | 56 +++++++++--------------------- src/Contracts/MessageTypes.ts | 48 ------------------------- src/hooks/useKnockoutExplorer.ts | 6 +--- 6 files changed, 66 insertions(+), 108 deletions(-) delete mode 100644 src/Contracts/MessageTypes.ts diff --git a/src/Common/CosmosClient.ts b/src/Common/CosmosClient.ts index b06f68f95..84d80b0e2 100644 --- a/src/Common/CosmosClient.ts +++ b/src/Common/CosmosClient.ts @@ -1,14 +1,13 @@ import * as Cosmos from "@azure/cosmos"; -import { sendCachedDataMessage } from "Common/MessageHandler"; -import { AuthorizationToken, MessageTypes } from "Contracts/MessageTypes"; -import { AuthType } from "../AuthType"; -import { PriorityLevel } from "../Common/Constants"; -import { Platform, configContext } from "../ConfigContext"; +import { configContext, Platform } from "../ConfigContext"; import { userContext } from "../UserContext"; import { logConsoleError } from "../Utils/NotificationConsoleUtils"; -import * as PriorityBasedExecutionUtils from "../Utils/PriorityBasedExecutionUtils"; import { EmulatorMasterKey, HttpHeaders } from "./Constants"; import { getErrorMessage } from "./ErrorHandlingUtils"; +import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility"; +import { PriorityLevel } from "../Common/Constants"; +import * as PriorityBasedExecutionUtils from "../Utils/PriorityBasedExecutionUtils"; +import { AuthType } from "../AuthType"; const _global = typeof self === "undefined" ? window : self; @@ -27,12 +26,6 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => { return decodeURIComponent(headers.authorization); } - if (configContext.platform === Platform.Fabric) { - const authorizationToken = await sendCachedDataMessage(MessageTypes.GetAuthorizationToken, [requestInfo]); - console.log('Response from Fabric: ', authorizationToken); - return authorizationToken; - } - if (userContext.masterKey) { // TODO This SDK method mutates the headers object. Find a better one or fix the SDK. await Cosmos.setAuthorizationTokenHeaderUsingMasterKey(verb, resourceId, resourceType, headers, EmulatorMasterKey); @@ -63,7 +56,7 @@ export const endpoint = () => { return userContext.endpoint || userContext?.databaseAccount?.properties?.documentEndpoint; }; -export async function getTokenFromAuthService(verb: string, resourceType: string, resourceId?: string): Promise { +export async function getTokenFromAuthService(verb: string, resourceType: string, resourceId?: string): Promise { try { const host = configContext.BACKEND_ENDPOINT; const response = await _global.fetch(host + "/api/guest/runtimeproxy/authorizationTokens", { diff --git a/src/Common/MessageHandler.ts b/src/Common/MessageHandler.ts index e32b31d6c..834e2d7b5 100644 --- a/src/Common/MessageHandler.ts +++ b/src/Common/MessageHandler.ts @@ -22,7 +22,7 @@ export function handleCachedDataMessage(message: any): void { if (messageContent.error != null) { cachedDataPromise.deferred.reject(messageContent.error); } else { - cachedDataPromise.deferred.resolve(messageContent.data); + cachedDataPromise.deferred.resolve(JSON.parse(messageContent.data)); } runGarbageCollector(); } diff --git a/src/Contracts/ExplorerContracts.ts b/src/Contracts/ExplorerContracts.ts index 8fc230f2d..fa286f1fc 100644 --- a/src/Contracts/ExplorerContracts.ts +++ b/src/Contracts/ExplorerContracts.ts @@ -1,7 +1,46 @@ -import { MessageTypes } from "Contracts/MessageTypes"; import * as ActionContracts from "./ActionContracts"; import * as Diagnostics from "./Diagnostics"; import * as Versions from "./Versions"; -export { ActionContracts, Diagnostics, MessageTypes, Versions }; +/** + * Messaging types used with Data Explorer <-> Portal communication + * and Hosted <-> Explorer communication + */ +export enum MessageTypes { + TelemetryInfo, + LogInfo, + RefreshResources, + AllDatabases, + CollectionsForDatabase, + RefreshOffers, + AllOffers, + UpdateLocationHash, + SingleOffer, + RefreshOffer, + UpdateAccountName, + ForbiddenError, + AadSignIn, + GetAccessAadRequest, + GetAccessAadResponse, + UpdateAccountSwitch, + UpdateDirectoryControl, + SwitchAccount, + SendNotification, + ClearNotification, + ExplorerClickEvent, + LoadingStatus, + GetArcadiaToken, + CreateWorkspace, + CreateSparkPool, + RefreshDatabaseAccount, + CloseTab, + OpenQuickstartBlade, + OpenPostgreSQLPasswordReset, + OpenPostgresNetworkingBlade, + OpenCosmosDBNetworkingBlade, + DisplayNPSSurvey, + OpenVCoreMongoNetworkingBlade, + OpenVCoreMongoConnectionStringsBlade, +} +export { ActionContracts, Diagnostics, Versions }; diff --git a/src/Contracts/FabricContract.ts b/src/Contracts/FabricContract.ts index 8ae6e93f6..61f5c0bdb 100644 --- a/src/Contracts/FabricContract.ts +++ b/src/Contracts/FabricContract.ts @@ -1,47 +1,25 @@ -import { AuthorizationToken, MessageTypes } from "./MessageTypes"; - export type FabricMessage = | { - type: "newContainer"; - databaseName: string; - } - | { - type: "initialize"; - connectionString: string | undefined; - } - | { - type: "openTab"; - databaseName: string; - collectionName: string | undefined; - } - | { - type: "authorizationToken"; - message: { - id: string; - error: string | undefined; - data: AuthorizationToken; + type: "newContainer"; + databaseName: string; } - }; + | { + type: "initialize"; + connectionString: string | undefined; + } + | { + type: "openTab"; + databaseName: string; + collectionName: string | undefined; + }; export type DataExploreMessage = | "ready" | { - type: MessageTypes.TelemetryInfo; - data: { - action: "LoadDatabases"; - actionModifier: "success" | "start"; - defaultExperience: "SQL"; + type: number; + data: { + action: "LoadDatabases"; + actionModifier: "success" | "start"; + defaultExperience: "SQL"; + }; }; - } - | { - type: MessageTypes.GetAuthorizationToken; - id: string; - params: [{ - verb: string; - resourceId: string; - resourceType: string; - headers: { - [key: string]: string; - } - }]; - }; diff --git a/src/Contracts/MessageTypes.ts b/src/Contracts/MessageTypes.ts deleted file mode 100644 index e9c3ed5a5..000000000 --- a/src/Contracts/MessageTypes.ts +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Messaging types used with Data Explorer <-> Portal communication, - * Hosted <-> Explorer communication and Data Explorer -> Fabric communication. - */ -export enum MessageTypes { - TelemetryInfo, - LogInfo, - RefreshResources, - AllDatabases, - CollectionsForDatabase, - RefreshOffers, - AllOffers, - UpdateLocationHash, - SingleOffer, - RefreshOffer, - UpdateAccountName, - ForbiddenError, - AadSignIn, - GetAccessAadRequest, - GetAccessAadResponse, - UpdateAccountSwitch, - UpdateDirectoryControl, - SwitchAccount, - SendNotification, - ClearNotification, - ExplorerClickEvent, - LoadingStatus, - GetArcadiaToken, - CreateWorkspace, - CreateSparkPool, - RefreshDatabaseAccount, - CloseTab, - OpenQuickstartBlade, - OpenPostgreSQLPasswordReset, - OpenPostgresNetworkingBlade, - OpenCosmosDBNetworkingBlade, - DisplayNPSSurvey, - OpenVCoreMongoNetworkingBlade, - OpenVCoreMongoConnectionStringsBlade, - - // Data Explorer -> Fabric communication - GetAuthorizationToken, -} - -export interface AuthorizationToken { - XDate: string; - PrimaryReadWriteToken: string; -} \ No newline at end of file diff --git a/src/hooks/useKnockoutExplorer.ts b/src/hooks/useKnockoutExplorer.ts index 715c85869..16d044105 100644 --- a/src/hooks/useKnockoutExplorer.ts +++ b/src/hooks/useKnockoutExplorer.ts @@ -10,7 +10,7 @@ import { useEffect, useState } from "react"; import { AuthType } from "../AuthType"; import { AccountKind, Flights } from "../Common/Constants"; import { normalizeArmEndpoint } from "../Common/EnvironmentUtility"; -import { handleCachedDataMessage, sendMessage, sendReadyMessage } from "../Common/MessageHandler"; +import { sendMessage, sendReadyMessage } from "../Common/MessageHandler"; import { Platform, configContext, updateConfigContext } from "../ConfigContext"; import { ActionType, DataExplorerAction, TabKind } from "../Contracts/ActionContracts"; import { MessageTypes } from "../Contracts/ExplorerContracts"; @@ -166,10 +166,6 @@ async function configureFabric(): Promise { break; } - case "authorizationToken": { - handleCachedDataMessage(data); - break; - } default: console.error(`Unknown Fabric message type: ${JSON.stringify(data)}`); break;