From a3f3511043201c8824989df04fd2ad813b88bd9e Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Thu, 23 May 2024 17:11:03 +0200 Subject: [PATCH] Reinstate get authorization token path which doesn't get called every 5 minutes anymore --- src/Common/CosmosClient.ts | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/Common/CosmosClient.ts b/src/Common/CosmosClient.ts index c24680f4b..2a1913c83 100644 --- a/src/Common/CosmosClient.ts +++ b/src/Common/CosmosClient.ts @@ -1,6 +1,7 @@ import * as Cosmos from "@azure/cosmos"; +import { sendCachedDataMessage } from "Common/MessageHandler"; import { getAuthorizationTokenUsingResourceTokens } from "Common/getAuthorizationTokenUsingResourceTokens"; -import { AuthorizationToken } from "Contracts/FabricMessageTypes"; +import { AuthorizationToken, FabricMessageTypes } from "Contracts/FabricMessageTypes"; import { checkDatabaseResourceTokensValidity } from "Platform/Fabric/FabricUtil"; import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility"; import { AuthType } from "../AuthType"; @@ -50,23 +51,15 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => { case Cosmos.ResourceType.offer: case Cosmos.ResourceType.user: case Cosmos.ResourceType.permission: - // For now, these operations aren't used, so fetching the authorization token is commented out. - // This provider must return a real token to pass validation by the client, so we return the cached resource token - // (which is a valid token, but won't work for these operations). - const resourceTokens2 = userContext.fabricContext.databaseConnectionInfo.resourceTokens; - return getAuthorizationTokenUsingResourceTokens(resourceTokens2, requestInfo.path, requestInfo.resourceId); - - /* ************** TODO: Uncomment this code if we need to support these operations ************** - // User master tokens - const authorizationToken = await sendCachedDataMessage( - FabricMessageTypes.GetAuthorizationToken, - [requestInfo], - userContext.fabricContext.connectionId, - ); - console.log("Response from Fabric: ", authorizationToken); - headers[HttpHeaders.msDate] = authorizationToken.XDate; - return decodeURIComponent(authorizationToken.PrimaryReadWriteToken); - ***********************************************************************************************/ + // User master tokens + const authorizationToken = await sendCachedDataMessage( + FabricMessageTypes.GetAuthorizationToken, + [requestInfo], + userContext.fabricContext.connectionId, + ); + console.log("Response from Fabric: ", authorizationToken); + headers[HttpHeaders.msDate] = authorizationToken.XDate; + return decodeURIComponent(authorizationToken.PrimaryReadWriteToken); } }