Allow dynamic MSAL Authority (#896)

This commit is contained in:
Steve Faulkner 2021-06-16 09:13:11 -05:00 committed by GitHub
parent 914c372f5b
commit 6f68c75257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 10 deletions

View File

@ -120,6 +120,14 @@ export async function initializeConfiguration(): Promise<ConfigContext> {
const armAPIVersion = params.get("armAPIVersion") || "";
updateConfigContext({ armAPIVersion });
}
if (params.has("armEndpoint")) {
const ARM_ENDPOINT = params.get("armEndpoint") || "";
updateConfigContext({ ARM_ENDPOINT });
}
if (params.has("aadEndpoint")) {
const AAD_ENDPOINT = params.get("aadEndpoint") || "";
updateConfigContext({ AAD_ENDPOINT });
}
if (params.has("platform")) {
const platform = params.get("platform");
switch (platform) {

View File

@ -2,6 +2,7 @@ import * as msal from "@azure/msal-browser";
import { AuthType } from "../AuthType";
import * as Constants from "../Common/Constants";
import * as Logger from "../Common/Logger";
import { configContext } from "../ConfigContext";
import * as ViewModels from "../Contracts/ViewModels";
import { userContext } from "../UserContext";
@ -48,7 +49,7 @@ export function getMsalInstance() {
cacheLocation: "localStorage",
},
auth: {
authority: "https://login.microsoftonline.com/common",
authority: `${configContext.AAD_ENDPOINT}common`,
clientId: "203f1145-856a-4232-83d4-a43568fba23d",
},
};

View File

@ -51,7 +51,7 @@ export function useAADAuth(): ReturnType {
async (id) => {
const response = await msalInstance.loginPopup({
redirectUri: configContext.msalRedirectURI,
authority: `https://login.microsoftonline.com/${id}`,
authority: `${configContext.AAD_ENDPOINT}${id}`,
scopes: [],
});
setTenantId(response.tenantId);
@ -64,12 +64,12 @@ export function useAADAuth(): ReturnType {
if (account && tenantId) {
Promise.all([
msalInstance.acquireTokenSilent({
authority: `https://login.microsoftonline.com/${tenantId}`,
scopes: ["https://graph.windows.net//.default"],
authority: `${configContext.AAD_ENDPOINT}${tenantId}`,
scopes: [`${configContext.GRAPH_ENDPOINT}/.default`],
}),
msalInstance.acquireTokenSilent({
authority: `https://login.microsoftonline.com/${tenantId}`,
scopes: ["https://management.azure.com//.default"],
authority: `${configContext.AAD_ENDPOINT}${tenantId}`,
scopes: [`${configContext.ARM_ENDPOINT}/.default`],
}),
]).then(([graphTokenResponse, armTokenResponse]) => {
setGraphToken(graphTokenResponse.accessToken);

View File

@ -1,4 +1,5 @@
import useSWR from "swr";
import { configContext } from "../ConfigContext";
import { DatabaseAccount } from "../Contracts/DataModels";
interface AccountListResult {
@ -14,7 +15,7 @@ export async function fetchDatabaseAccounts(subscriptionId: string, accessToken:
let accounts: Array<DatabaseAccount> = [];
let nextLink = `https://management.azure.com/subscriptions/${subscriptionId}/providers/Microsoft.DocumentDB/databaseAccounts?api-version=2020-06-01-preview`;
let nextLink = `${configContext.ARM_ENDPOINT}/subscriptions/${subscriptionId}/providers/Microsoft.DocumentDB/databaseAccounts?api-version=2020-06-01-preview`;
while (nextLink) {
const response: Response = await fetch(nextLink, { headers });

View File

@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
import { configContext } from "../ConfigContext";
import { Tenant } from "../Contracts/DataModels";
interface TenantListResult {
@ -13,7 +14,7 @@ export async function fetchDirectories(accessToken: string): Promise<Tenant[]> {
headers.append("Authorization", bearer);
let tenents: Array<Tenant> = [];
let nextLink = `https://management.azure.com/tenants?api-version=2020-01-01`;
let nextLink = `${configContext.ARM_ENDPOINT}/tenants?api-version=2020-01-01`;
while (nextLink) {
const response = await fetch(nextLink, { headers });

View File

@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
import { configContext } from "../ConfigContext";
export async function fetchPhoto(accessToken: string): Promise<Blob | void> {
const headers = new Headers();
@ -12,7 +13,7 @@ export async function fetchPhoto(accessToken: string): Promise<Blob | void> {
headers: headers,
};
return fetch("https://graph.windows.net/me/thumbnailPhoto?api-version=1.6", options).then((response) =>
return fetch(`${configContext.GRAPH_ENDPOINT}/me/thumbnailPhoto?api-version=1.6`, options).then((response) =>
response.blob()
);
}

View File

@ -1,4 +1,5 @@
import useSWR from "swr";
import { configContext } from "../ConfigContext";
import { Subscription } from "../Contracts/DataModels";
interface SubscriptionListResult {
@ -13,7 +14,7 @@ export async function fetchSubscriptions(accessToken: string): Promise<Subscript
headers.append("Authorization", bearer);
let subscriptions: Array<Subscription> = [];
let nextLink = `https://management.azure.com/subscriptions?api-version=2020-01-01`;
let nextLink = `${configContext.ARM_ENDPOINT}subscriptions?api-version=2020-01-01`;
while (nextLink) {
const response = await fetch(nextLink, { headers });