Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user data boundary identification #524

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 62 additions & 3 deletions src/scripts/extensions/authenticationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -66,21 +67,19 @@ 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);

this.user.set({ updateReason: updateReason });
}).then(() => {
this.logger.logEvent(getInfoEvent);

resolve(this.user.get());
});
});
Expand Down Expand Up @@ -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<string | undefined> {
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;
}
}
}
}
6 changes: 6 additions & 0 deletions src/scripts/extensions/dataBoundary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum DataBoundary {
PUBLIC,
GLOBAL,
EUDB,
EMEA,
}
3 changes: 2 additions & 1 deletion src/scripts/logging/submodules/propertyName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export module PropertyName {
UserUpdateReason,
Value,
Width,
WriteableCookies
WriteableCookies,
dataBoundary
}

/* tslint:disable:variable-name */
Expand Down
1 change: 1 addition & 0 deletions src/scripts/userInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface UserInfoData {
cookieInRequest?: boolean;
emailAddress?: string;
fullName?: string;
dataBoundary?: string;
}

export enum UpdateReason {
Expand Down