mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-28 05:11:31 +00:00
Added Auth
This commit is contained in:
@@ -2543,7 +2543,6 @@ export default class Explorer {
|
||||
const databaseAccountLocation = databaseAccount && databaseAccount.location.toLowerCase();
|
||||
const disallowedLocationsUri = `${configContext.BACKEND_ENDPOINT}/api/disallowedLocations`;
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
console.log("auth header:" + JSON.stringify(authorizationHeader));
|
||||
try {
|
||||
const response = await fetch(disallowedLocationsUri, {
|
||||
method: "POST",
|
||||
|
||||
@@ -1,20 +1,75 @@
|
||||
import "./Shared/appInsights";
|
||||
import * as _ from "underscore";
|
||||
import * as ko from "knockout";
|
||||
import { MessageTypes } from "./Contracts/ExplorerContracts";
|
||||
import * as ViewModels from "./Contracts/ViewModels";
|
||||
import "../less/hostedexplorer.less";
|
||||
import "./Explorer/Menus/NavBar/MeControlComponent.less";
|
||||
import * as ViewModels from "./Contracts/ViewModels";
|
||||
import { ClientSecretCredential } from "@azure/identity";
|
||||
import { CosmosDBManagementClient } from "@azure/arm-cosmosdb";
|
||||
import * as msRest from "@azure/ms-rest-js";
|
||||
import { DatabaseAccountsGetResponse } from "@azure/arm-cosmosdb/esm/models";
|
||||
import { TestExplorerParams } from "./TestExplorerParams";
|
||||
|
||||
class CustomSigner implements msRest.ServiceClientCredentials {
|
||||
private token: string;
|
||||
constructor(token: string) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
async signRequest(webResource: msRest.WebResourceLike): Promise<msRest.WebResourceLike> {
|
||||
webResource.headers.set("authorization", `bearer ${this.token}`);
|
||||
return webResource;
|
||||
}
|
||||
}
|
||||
|
||||
class TestExplorer {
|
||||
public isButtonVisible: ko.Observable<boolean>;
|
||||
private notebooksTestRunnerApplicationId: string;
|
||||
private notebooksTestRunnerClientId: string;
|
||||
private notebooksTestRunnerClientSecret: string;
|
||||
private notebooksAccountName: string;
|
||||
private notebooksAccountKey: string;
|
||||
private notebooksAccountSubscriptonId: string;
|
||||
private notebooksAccountResourceGroup: string;
|
||||
|
||||
constructor() {
|
||||
this.isButtonVisible = ko.observable(true);
|
||||
window.onload = () => {
|
||||
this.initTestExplorer();
|
||||
};
|
||||
window.addEventListener("message", this.handleMessage.bind(this), false);
|
||||
}
|
||||
|
||||
private parseUrlParams = (): void => {
|
||||
window.location.search
|
||||
.substr(1)
|
||||
.split("&")
|
||||
.forEach((item) => {
|
||||
const tmp = item.split("=");
|
||||
const value = decodeURIComponent(tmp[1]);
|
||||
switch (tmp[0]) {
|
||||
case TestExplorerParams.notebooksTestRunnerApplicationId:
|
||||
this.notebooksTestRunnerApplicationId = value;
|
||||
break;
|
||||
case TestExplorerParams.notebooksTestRunnerClientId:
|
||||
this.notebooksTestRunnerClientId = value;
|
||||
break;
|
||||
case TestExplorerParams.notebooksTestRunnerClientSecret:
|
||||
this.notebooksTestRunnerClientSecret = value;
|
||||
break;
|
||||
case TestExplorerParams.notebooksAccountName:
|
||||
this.notebooksAccountName = value;
|
||||
break;
|
||||
case TestExplorerParams.notebooksAccountKey:
|
||||
this.notebooksAccountKey = value;
|
||||
break;
|
||||
case TestExplorerParams.notebooksAccountSubscriptonId:
|
||||
this.notebooksAccountSubscriptonId = value;
|
||||
break;
|
||||
case TestExplorerParams.notebooksAccountResourceGroup:
|
||||
this.notebooksAccountResourceGroup = value;
|
||||
break;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
private handleMessage(event: MessageEvent) {
|
||||
if (event.data.type === MessageTypes.InitTestExplorer || event.data.type === MessageTypes.HideConnectScreen) {
|
||||
this.sendMessageToExplorerFrame(event.data);
|
||||
@@ -22,253 +77,33 @@ class TestExplorer {
|
||||
}
|
||||
|
||||
private async AADLogin(): Promise<string> {
|
||||
const tenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47";
|
||||
const clientId = "fd8753b0-0707-4e32-84e9-2532af865fb4";
|
||||
const clientSecret = "xGT82g3sO4AJ.C~G6dii5LP~6-yCit9J-h";
|
||||
|
||||
const credentials = new ClientSecretCredential(tenantId, clientId, clientSecret);
|
||||
|
||||
const credentials = new ClientSecretCredential(
|
||||
this.notebooksTestRunnerApplicationId,
|
||||
this.notebooksTestRunnerClientId,
|
||||
this.notebooksTestRunnerClientSecret
|
||||
);
|
||||
const token = await credentials.getToken("https://management.core.windows.net/.default");
|
||||
|
||||
return token.token;
|
||||
}
|
||||
|
||||
public async postMessage(): Promise<void> {
|
||||
private async getDatabaseAccount(token: string): Promise<DatabaseAccountsGetResponse> {
|
||||
const client = new CosmosDBManagementClient(new CustomSigner(token), this.notebooksAccountSubscriptonId);
|
||||
return await client.databaseAccounts.get(this.notebooksAccountResourceGroup, this.notebooksAccountName);
|
||||
}
|
||||
|
||||
private async initTestExplorer(): Promise<void> {
|
||||
this.parseUrlParams();
|
||||
const token = await this.AADLogin();
|
||||
const databaseAccount = await this.getDatabaseAccount(token);
|
||||
|
||||
const content = {
|
||||
type: MessageTypes.InitTestExplorer,
|
||||
inputs: {
|
||||
databaseAccount: {
|
||||
id:
|
||||
"/subscriptions/18f84a75-22a7-487c-a800-4e1bdad7779a/resourceGroups/srnara-cassandra-test/providers/Microsoft.DocumentDB/databaseAccounts/srnara-notebook",
|
||||
name: "srnara-notebook",
|
||||
location: "East US",
|
||||
type: "Microsoft.DocumentDB/databaseAccounts",
|
||||
kind: "GlobalDocumentDB",
|
||||
tags: { defaultExperience: "Core (SQL)" },
|
||||
systemData: { createdAt: "2019-10-16T20:46:11.4096965Z" },
|
||||
properties: {
|
||||
provisioningState: "Succeeded",
|
||||
documentEndpoint: "https://srnara-notebook.documents.azure.com:443/",
|
||||
publicNetworkAccess: "Enabled",
|
||||
enableAutomaticFailover: false,
|
||||
enableMultipleWriteLocations: true,
|
||||
enablePartitionKeyMonitor: false,
|
||||
isVirtualNetworkFilterEnabled: false,
|
||||
virtualNetworkRules: [],
|
||||
EnabledApiTypes: "Sql",
|
||||
disableKeyBasedMetadataWriteAccess: false,
|
||||
enableFreeTier: false,
|
||||
enableAnalyticalStorage: true,
|
||||
instanceId: "41978508-99b1-477d-9205-2d2f1ce7fc1a",
|
||||
createMode: "Default",
|
||||
databaseAccountOfferType: "Standard",
|
||||
consistencyPolicy: { defaultConsistencyLevel: "Session", maxIntervalInSeconds: 5, maxStalenessPrefix: 100 },
|
||||
configurationOverrides: {},
|
||||
writeLocations: [
|
||||
{
|
||||
id: "srnara-notebook-eastus",
|
||||
locationName: "East US",
|
||||
documentEndpoint: "https://srnara-notebook-eastus.documents.azure.com:443/",
|
||||
provisioningState: "Succeeded",
|
||||
failoverPriority: 0,
|
||||
isZoneRedundant: false
|
||||
}
|
||||
],
|
||||
readLocations: [
|
||||
{
|
||||
id: "srnara-notebook-eastus",
|
||||
locationName: "East US",
|
||||
documentEndpoint: "https://srnara-notebook-eastus.documents.azure.com:443/",
|
||||
provisioningState: "Succeeded",
|
||||
failoverPriority: 0,
|
||||
isZoneRedundant: false
|
||||
}
|
||||
],
|
||||
locations: [
|
||||
{
|
||||
id: "srnara-notebook-eastus",
|
||||
locationName: "East US",
|
||||
documentEndpoint: "https://srnara-notebook-eastus.documents.azure.com:443/",
|
||||
provisioningState: "Succeeded",
|
||||
failoverPriority: 0,
|
||||
isZoneRedundant: false
|
||||
}
|
||||
],
|
||||
failoverPolicies: [{ id: "srnara-notebook-eastus", locationName: "East US", failoverPriority: 0 }],
|
||||
cors: [],
|
||||
capabilities: [],
|
||||
ipRules: [],
|
||||
backupPolicy: {
|
||||
type: "Periodic",
|
||||
periodicModeProperties: { backupIntervalInMinutes: 240, backupRetentionIntervalInHours: 8 }
|
||||
}
|
||||
}
|
||||
},
|
||||
subscriptionId: "18f84a75-22a7-487c-a800-4e1bdad7779a",
|
||||
resourceGroup: "srnara-cassandra-test",
|
||||
databaseAccount: databaseAccount,
|
||||
subscriptionId: this.notebooksAccountSubscriptonId,
|
||||
resourceGroup: this.notebooksAccountResourceGroup,
|
||||
authorizationToken: `Bearer ${token}`,
|
||||
features: {
|
||||
cacheextensionapp: "false",
|
||||
detailednetworktelemetry: "false",
|
||||
logexternaldomainlinks: "true",
|
||||
enableextensionpreviewstamp: "true",
|
||||
gctelemetry: "false",
|
||||
mereactblade: "true",
|
||||
paralleltokens: "false",
|
||||
prefetchbrowsequerymanifest: "false",
|
||||
prefetchtokensinparallel: "true",
|
||||
pretick: "false",
|
||||
reactdatafetch: "false",
|
||||
shellworker: "true",
|
||||
shellworkerassets: "true",
|
||||
shellworkerbrowseprereqs: "true",
|
||||
shellworkersubs: "true",
|
||||
simplebatch: "false",
|
||||
storageperf1: "false",
|
||||
storageperf2: "false",
|
||||
earlymenucontentvm: "false",
|
||||
bladefullrenderx: "false",
|
||||
controlstelemetry: "true",
|
||||
noeffectflight: "true",
|
||||
advisornotificationdays: "30",
|
||||
advisornotificationpercent: "100",
|
||||
allserviceswithoverview: "true",
|
||||
argsharedqueries: "true",
|
||||
argsubscriptions: "true",
|
||||
armviewer: "true",
|
||||
asyncsearch: "true",
|
||||
azureconsole: "true",
|
||||
azurehome: "true",
|
||||
columnchooserreact: "true",
|
||||
contactinfo: "true",
|
||||
custombingsearch: "true",
|
||||
dashboardalphaapi: "true",
|
||||
dashboardautorefresh: "true",
|
||||
dashboardautorefreshinterval: "60",
|
||||
dashboardfeedback: "true",
|
||||
dashboardnewpinexperience: "true",
|
||||
dashboardpreviewapi: "true",
|
||||
dashboardrefresh: "true",
|
||||
devsatsurvey: "true",
|
||||
deploy2020: "true",
|
||||
enableregionmove: "true",
|
||||
enablestartswithmdm: "true",
|
||||
enhancedprint: "true",
|
||||
essentialsjsonview: "true",
|
||||
freelancer: "true",
|
||||
guidedtour: "true",
|
||||
helpcontentwhatsnewenabled: "true",
|
||||
hidefavoritestars: "true",
|
||||
hostingservicesuffix: "mpac",
|
||||
hubsresourceaccessfromconfig: "true",
|
||||
internalonly: "nobanner",
|
||||
iriscore: "true",
|
||||
iriscorealt: "true",
|
||||
iriscoresurfacename: "88000327",
|
||||
irissurfacename: "AzurePortal_Notifications_Preview",
|
||||
landalltohome: "true",
|
||||
loggraphcallwitharmtoken: "true",
|
||||
meazblade: "true",
|
||||
mistendpoint: "https://mist.int.monitor.azure.com",
|
||||
nojqueryeval: "true",
|
||||
nopdlearlymenucontentbundles: "true",
|
||||
npsintervaldays: "90",
|
||||
npspercent: "2.4",
|
||||
npsshowportaluri: "true",
|
||||
policyawarecontrols: "true",
|
||||
prefetchtokens: "true",
|
||||
prewarmingtesting: "true",
|
||||
reactviewendpointindex: "1",
|
||||
reloadafterdays: "5",
|
||||
serverfetchedevents: "true",
|
||||
sessionvalidity: "true",
|
||||
settingsportalinstance: "mpac",
|
||||
shadowargcall: "true",
|
||||
showbugreportlink: "true",
|
||||
showhovercard: "true",
|
||||
sidebarhamburgermode: "true",
|
||||
singlesignout: "true",
|
||||
subscreditcheck: "true",
|
||||
tenants2020: "true",
|
||||
tilegallerycuration: "true",
|
||||
upgradefromtrialbutton: "true",
|
||||
argbrowseviews: "true",
|
||||
argforoldbrowse: "true",
|
||||
argforrgoverview: "true",
|
||||
argtagsfilter: "true",
|
||||
artbrowse: "true",
|
||||
automationtasks: "true",
|
||||
browsecuration: "default",
|
||||
browsedialogcompactpills: "true",
|
||||
browsedialogpills: "true",
|
||||
browsefilterstelemetry: "true",
|
||||
bypasstokencacheforcustomsignin: "true",
|
||||
cloudsimplereservations: "true",
|
||||
contactabilitybycountry: "true",
|
||||
cryptoapihash: "true",
|
||||
dashboardfilters: "true",
|
||||
dashboardfiltersaddbutton: "true",
|
||||
devnps: "true",
|
||||
devnpsintervaldays: "45",
|
||||
devnpspercent: "50.0",
|
||||
enableaeoemails: "false",
|
||||
enablee2emonitoring: "true",
|
||||
enablelocationchange: "true",
|
||||
experimentation: "false",
|
||||
failajaxonnulltoken: "true",
|
||||
fastencode: "true",
|
||||
feedback: "true",
|
||||
feedbackwithsupport: "true",
|
||||
fullscreenblades: "true",
|
||||
hidemodalsonsmallscreens: "true",
|
||||
hidemodalswhendeeplinked: "true",
|
||||
irismessagelimit: "1",
|
||||
isworkbooksavailable: "true",
|
||||
migratetomsal: "true",
|
||||
mspexpert: "true",
|
||||
mspfilter: "true",
|
||||
mspinfo: "true",
|
||||
newresourceapi: "true",
|
||||
newsupportblade: "true",
|
||||
nps: "true",
|
||||
outagebanner: "true",
|
||||
portalpolling: "true",
|
||||
preact: "true",
|
||||
preferredusername: "true",
|
||||
prefetchdrafttoken: "true",
|
||||
prefetchrecents: "true",
|
||||
providers2019: "true",
|
||||
pushtokens: "true",
|
||||
removesubsdropdownlimit: "true",
|
||||
reservationsinbrowse: "true",
|
||||
reservehozscroll: "true",
|
||||
resourcehealth: "true",
|
||||
savedeploymentnotification: "true",
|
||||
seetemplate: "true",
|
||||
serveravatar: "true",
|
||||
showpostcreatefeedbackoption: "true",
|
||||
showservicehealthalerts: "true",
|
||||
showworkflowappkindbrowse: "true",
|
||||
supplementalbatchsize: "20",
|
||||
tenantscoperedirect: "true",
|
||||
tokencaching: "true",
|
||||
usealertsv2blade: "true",
|
||||
usemsallogin: "true",
|
||||
zerosubsexperience: "true",
|
||||
regionsegments: "true",
|
||||
allservicesweave: "false",
|
||||
bundlingkind: "DefaultPartitioner",
|
||||
confighash: "CGZNcAynkOLM",
|
||||
env: "ms",
|
||||
l: "en.en-us",
|
||||
pageversion: "6.659.0.25051.201105-0922",
|
||||
prefetchhome: "false",
|
||||
prewarmie: "false",
|
||||
weaveblade: "true",
|
||||
dataexplorersource: "https://localhost:1234/explorer.html",
|
||||
experimentationflights: "settingsv2;mongoindexeditor"
|
||||
},
|
||||
features: {},
|
||||
hasWriteAccess: true,
|
||||
csmEndpoint: "https://management.azure.com",
|
||||
dnsSuffix: "documents.azure.com",
|
||||
@@ -278,7 +113,7 @@ class TestExplorer {
|
||||
quotaId: "Internal_2014-09-01",
|
||||
addCollectionDefaultFlight: "2",
|
||||
isTryCosmosDBSubscription: false,
|
||||
masterKey: "jB16xFppH34oIsrxhKytgqlGdq4n3UcHAD9J20jNosrOAzDKfAcvM1kfeBM49ccFxjpFW85Du2ISvrjdl7i4fg==",
|
||||
masterKey: this.notebooksAccountKey,
|
||||
loadDatabaseAccountTimestamp: 1604663109836,
|
||||
dataExplorerVersion: "1.0.1",
|
||||
sharedThroughputMinimum: 400,
|
||||
@@ -297,10 +132,9 @@ class TestExplorer {
|
||||
type: MessageTypes.HideConnectScreen
|
||||
};
|
||||
window.postMessage(hideConnectContent, window.location.href);
|
||||
this.isButtonVisible(false);
|
||||
}
|
||||
|
||||
private sendMessageToExplorerFrame(data: any): void {
|
||||
private sendMessageToExplorerFrame(data: unknown): void {
|
||||
const explorerFrame = document.getElementById("explorerMenu") as HTMLIFrameElement;
|
||||
explorerFrame &&
|
||||
explorerFrame.contentDocument &&
|
||||
|
||||
9
src/TestExplorerParams.ts
Normal file
9
src/TestExplorerParams.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export enum TestExplorerParams {
|
||||
notebooksTestRunnerApplicationId = "notebooksTestRunnerApplicationId",
|
||||
notebooksTestRunnerClientId = "notebooksTestRunnerClientId",
|
||||
notebooksTestRunnerClientSecret = "notebooksTestRunnerClientSecret",
|
||||
notebooksAccountName = "notebooksAccountName",
|
||||
notebooksAccountKey = "notebooksAccountKey",
|
||||
notebooksAccountSubscriptonId = "notebooksAccountSubscriptonId",
|
||||
notebooksAccountResourceGroup = "notebooksAccountResourceGroup"
|
||||
}
|
||||
@@ -9,14 +9,7 @@
|
||||
<body>
|
||||
<switch-directory-pane params="{data: switchDirectoryPane}"></switch-directory-pane>
|
||||
|
||||
<button data-bind="click: postMessage, visible: isButtonVisible">Test login</button>
|
||||
<iframe
|
||||
id="explorerMenu"
|
||||
name="explorer"
|
||||
class="iframe"
|
||||
title="explorer"
|
||||
src="explorer.html?v=1.0.1&platform=Hosted"
|
||||
>
|
||||
<iframe id="explorerMenu" name="explorer" class="iframe" title="explorer" src="explorer.html?v=1.0.1&platform=Test">
|
||||
</iframe>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user