From bdf940f70162f5b67f7505a65831ecb9e207836f Mon Sep 17 00:00:00 2001 From: Akhilesh Garg Date: Sun, 2 Apr 2023 13:51:07 -0700 Subject: [PATCH] user data boundary identification --- .../extensions/authenticationHelper.ts | 65 ++++++++++++++++++- src/scripts/extensions/dataBoundary.ts | 6 ++ .../logging/submodules/propertyName.ts | 3 +- src/scripts/userInfo.ts | 1 + 4 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 src/scripts/extensions/dataBoundary.ts diff --git a/src/scripts/extensions/authenticationHelper.ts b/src/scripts/extensions/authenticationHelper.ts index 4fba9b78..b6299fe2 100644 --- a/src/scripts/extensions/authenticationHelper.ts +++ b/src/scripts/extensions/authenticationHelper.ts @@ -16,6 +16,7 @@ import {ResponsePackage} from "../responsePackage"; import {StringUtils} from "../stringUtils"; import {UserInfoData} from "../userInfo"; import {UrlUtils} from "../urlUtils"; +import { DataBoundary } from "./DataBoundary"; declare var browser; @@ -66,13 +67,12 @@ export class AuthenticationHelper { getInfoEvent.setCustomProperty(Log.PropertyName.Custom.WriteableCookies, writeableCookies); getInfoEvent.setCustomProperty(Log.PropertyName.Custom.UserUpdateReason, UpdateReason[updateReason]); - if (isValidUser) { + response.data.dataBoundary = this.getUserDataBoundary(response.data); this.user.set({ user: response.data, lastUpdated: response.lastUpdated, updateReason: updateReason, writeableCookies: writeableCookies }); } else { this.user.set({ updateReason: updateReason, writeableCookies: writeableCookies }); } - }, (error: OneNoteApi.GenericError) => { getInfoEvent.setStatus(Log.Status.Failed); getInfoEvent.setFailureInfo(error); @@ -80,7 +80,6 @@ export class AuthenticationHelper { this.user.set({ updateReason: updateReason }); }).then(() => { this.logger.logEvent(getInfoEvent); - resolve(this.user.get()); }); }); @@ -139,4 +138,64 @@ export class AuthenticationHelper { // Note that we are returning true by default to ensure the N-1 scenario. return userInfo.cookieInRequest !== undefined ? userInfo.cookieInRequest : true; } + + /** + * fetch the user data bounday from the emailAddress + * @param userInfo + * @returns user data boudary + */ + protected async getUserDataBoundary(userInfo : UserInfoData) : Promise { + try { + if (!userInfo) { + console.log("user Info undefined !"); + return undefined; + } + if (AuthType.Msa.toString() == userInfo.authType) { + console.log("Auth type MSA"); + return DataBoundary.EMEA.toString(); + } + let domainValue; + if (!userInfo || !userInfo.emailAddress) { + console.log("getUserDataBoundary null emailAddresss"); + } else { + domainValue = userInfo.emailAddress.substring( + userInfo.emailAddress.indexOf('@') + 1 + ); + } + console.log("getUserDataBoundary domainValue : " + domainValue); + let mailHrdApi = "https://odc.officeapps.live.com/odc/v2.1/federationprovider"; + const queryParams: { [key: string]: string } = { domain: domainValue } + if (queryParams) { + for (const key of Object.keys(queryParams)) { + const queryParam = queryParams[key]; + if (queryParam) { + mailHrdApi = UrlUtils.addUrlQueryValue(mailHrdApi, key, queryParam); + } + } + } + // 👇️ const response: Response + const response = await fetch(mailHrdApi, { + method: 'GET', + headers: { + Accept: 'application/json', + }, + }); + if (!response.ok) { + console.log("getUserDataBoundary response not ok!"); + return undefined; + } + let result = await response.json(); + let telemetryRegion = result.telemetryRegion + console.log("telemetryRegion: " + telemetryRegion); + return telemetryRegion; + } catch (error) { + if (error instanceof Error) { + console.log('error message: ', error.message); + return undefined; + } else { + console.log('unexpected error: ', error); + return undefined; + } + } + } } diff --git a/src/scripts/extensions/dataBoundary.ts b/src/scripts/extensions/dataBoundary.ts new file mode 100644 index 00000000..dd85d912 --- /dev/null +++ b/src/scripts/extensions/dataBoundary.ts @@ -0,0 +1,6 @@ +export enum DataBoundary { + PUBLIC, + GLOBAL, + EUDB, + EMEA, + } \ No newline at end of file diff --git a/src/scripts/logging/submodules/propertyName.ts b/src/scripts/logging/submodules/propertyName.ts index d85784ae..a59eca7e 100644 --- a/src/scripts/logging/submodules/propertyName.ts +++ b/src/scripts/logging/submodules/propertyName.ts @@ -57,7 +57,8 @@ export module PropertyName { UserUpdateReason, Value, Width, - WriteableCookies + WriteableCookies, + dataBoundary } /* tslint:disable:variable-name */ diff --git a/src/scripts/userInfo.ts b/src/scripts/userInfo.ts index bfa0c299..6dca58e7 100644 --- a/src/scripts/userInfo.ts +++ b/src/scripts/userInfo.ts @@ -19,6 +19,7 @@ export interface UserInfoData { cookieInRequest?: boolean; emailAddress?: string; fullName?: string; + dataBoundary?: string; } export enum UpdateReason {