Allow dynamic MSAL Authority (#896)
This commit is contained in:
parent
914c372f5b
commit
6f68c75257
|
@ -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) {
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 });
|
||||
|
|
Loading…
Reference in New Issue