From 6add6d2e860bc85645f2804315c4fa427ee677f7 Mon Sep 17 00:00:00 2001 From: Bala Lakshmi Narayanasami Date: Mon, 9 May 2022 18:50:04 +0530 Subject: [PATCH] Changes for getting conversation token --- src/ConfigContext.ts | 3 ++- .../SupportPaneComponent.tsx | 2 -- src/Explorer/Explorer.tsx | 20 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/ConfigContext.ts b/src/ConfigContext.ts index e492a3d13..a226b9794 100644 --- a/src/ConfigContext.ts +++ b/src/ConfigContext.ts @@ -9,7 +9,7 @@ import { allowedJunoOrigins, allowedMongoBackendEndpoints, allowedMsalRedirectEndpoints, - validateEndpoint, + validateEndpoint } from "Utils/EndpointValidation"; export enum Platform { @@ -190,3 +190,4 @@ export async function initializeConfiguration(): Promise { } export { configContext }; + diff --git a/src/Explorer/Controls/SupportPaneComponent/SupportPaneComponent.tsx b/src/Explorer/Controls/SupportPaneComponent/SupportPaneComponent.tsx index 10ac2f949..7f8fc542d 100644 --- a/src/Explorer/Controls/SupportPaneComponent/SupportPaneComponent.tsx +++ b/src/Explorer/Controls/SupportPaneComponent/SupportPaneComponent.tsx @@ -30,13 +30,11 @@ export class SupportPaneComponent extends React.Component { - // Add whatever needs to be added. activity.channelData.token = this.props.userToken; activity.channelData.subId = this.props.subId; activity.channelData.rg = this.props.rg; activity.channelData.accName = this.props.accName; - //activity.channelData.MyKey = "hello"; return directLine.postActivity(activity) } } diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index 12b1ea175..ad904ffe6 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -1,5 +1,6 @@ import { Link } from "@fluentui/react/lib/Link"; import { isPublicInternetAccessAllowed } from "Common/DatabaseAccountUtility"; +import { configContext } from "ConfigContext"; import { IGalleryItem } from "Juno/JunoClient"; import * as ko from "knockout"; import React from "react"; @@ -34,6 +35,7 @@ import { userContext } from "../UserContext"; import { getCollectionName, getUploadName } from "../Utils/APITypeUtils"; import { update } from "../Utils/arm/generatedClients/cosmos/databaseAccounts"; import { listByDatabaseAccount } from "../Utils/arm/generatedClients/cosmosNotebooks/notebookWorkspaces"; +import { getAuthorizationHeader } from "../Utils/AuthorizationUtils"; import { stringToBlob } from "../Utils/BlobUtils"; import { isCapabilityEnabled } from "../Utils/CapabilityUtils"; import { fromContentUri, toRawContentUri } from "../Utils/GitHubUtils"; @@ -479,26 +481,24 @@ export default class Explorer { name = tokenPayload.name; } } catch (error) { - // ignore + console.error("Exception while decrypting token"); + console.error(error); } finally { return name; } } private async generateConversationToken() { - const response = await fetch("https://directline.botframework.com/v3/directline/tokens/generate", { - method: "POST", + var url = `${configContext.JUNO_ENDPOINT}/api/chatbot/bot${userContext.databaseAccount.id}/conversationToken`; + const authorizationHeader = getAuthorizationHeader(); + + const response = await fetch(url, { + method: "GET", headers: { - [Constants.HttpHeaders.authorization]: "Bearer BSjLmJJHZRA.PxahjJGCNOKl7q9tiodWyVcqJOIzG894vAAqCme639o", + [Constants.HttpHeaders.authorization]: authorizationHeader.token, Accept: "application/json", [Constants.HttpHeaders.contentType]: "application/json" }, - body: JSON.stringify({ - "user": { - "id": `dl_${_.uniqueId()}`, - "name": this.getUserName() - } - }) }); if (!response.ok) {