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") || "";
|
const armAPIVersion = params.get("armAPIVersion") || "";
|
||||||
updateConfigContext({ 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")) {
|
if (params.has("platform")) {
|
||||||
const platform = params.get("platform");
|
const platform = params.get("platform");
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as msal from "@azure/msal-browser";
|
||||||
import { AuthType } from "../AuthType";
|
import { AuthType } from "../AuthType";
|
||||||
import * as Constants from "../Common/Constants";
|
import * as Constants from "../Common/Constants";
|
||||||
import * as Logger from "../Common/Logger";
|
import * as Logger from "../Common/Logger";
|
||||||
|
import { configContext } from "../ConfigContext";
|
||||||
import * as ViewModels from "../Contracts/ViewModels";
|
import * as ViewModels from "../Contracts/ViewModels";
|
||||||
import { userContext } from "../UserContext";
|
import { userContext } from "../UserContext";
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ export function getMsalInstance() {
|
||||||
cacheLocation: "localStorage",
|
cacheLocation: "localStorage",
|
||||||
},
|
},
|
||||||
auth: {
|
auth: {
|
||||||
authority: "https://login.microsoftonline.com/common",
|
authority: `${configContext.AAD_ENDPOINT}common`,
|
||||||
clientId: "203f1145-856a-4232-83d4-a43568fba23d",
|
clientId: "203f1145-856a-4232-83d4-a43568fba23d",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,7 +51,7 @@ export function useAADAuth(): ReturnType {
|
||||||
async (id) => {
|
async (id) => {
|
||||||
const response = await msalInstance.loginPopup({
|
const response = await msalInstance.loginPopup({
|
||||||
redirectUri: configContext.msalRedirectURI,
|
redirectUri: configContext.msalRedirectURI,
|
||||||
authority: `https://login.microsoftonline.com/${id}`,
|
authority: `${configContext.AAD_ENDPOINT}${id}`,
|
||||||
scopes: [],
|
scopes: [],
|
||||||
});
|
});
|
||||||
setTenantId(response.tenantId);
|
setTenantId(response.tenantId);
|
||||||
|
@ -64,12 +64,12 @@ export function useAADAuth(): ReturnType {
|
||||||
if (account && tenantId) {
|
if (account && tenantId) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
msalInstance.acquireTokenSilent({
|
msalInstance.acquireTokenSilent({
|
||||||
authority: `https://login.microsoftonline.com/${tenantId}`,
|
authority: `${configContext.AAD_ENDPOINT}${tenantId}`,
|
||||||
scopes: ["https://graph.windows.net//.default"],
|
scopes: [`${configContext.GRAPH_ENDPOINT}/.default`],
|
||||||
}),
|
}),
|
||||||
msalInstance.acquireTokenSilent({
|
msalInstance.acquireTokenSilent({
|
||||||
authority: `https://login.microsoftonline.com/${tenantId}`,
|
authority: `${configContext.AAD_ENDPOINT}${tenantId}`,
|
||||||
scopes: ["https://management.azure.com//.default"],
|
scopes: [`${configContext.ARM_ENDPOINT}/.default`],
|
||||||
}),
|
}),
|
||||||
]).then(([graphTokenResponse, armTokenResponse]) => {
|
]).then(([graphTokenResponse, armTokenResponse]) => {
|
||||||
setGraphToken(graphTokenResponse.accessToken);
|
setGraphToken(graphTokenResponse.accessToken);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
import { configContext } from "../ConfigContext";
|
||||||
import { DatabaseAccount } from "../Contracts/DataModels";
|
import { DatabaseAccount } from "../Contracts/DataModels";
|
||||||
|
|
||||||
interface AccountListResult {
|
interface AccountListResult {
|
||||||
|
@ -14,7 +15,7 @@ export async function fetchDatabaseAccounts(subscriptionId: string, accessToken:
|
||||||
|
|
||||||
let accounts: Array<DatabaseAccount> = [];
|
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) {
|
while (nextLink) {
|
||||||
const response: Response = await fetch(nextLink, { headers });
|
const response: Response = await fetch(nextLink, { headers });
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { configContext } from "../ConfigContext";
|
||||||
import { Tenant } from "../Contracts/DataModels";
|
import { Tenant } from "../Contracts/DataModels";
|
||||||
|
|
||||||
interface TenantListResult {
|
interface TenantListResult {
|
||||||
|
@ -13,7 +14,7 @@ export async function fetchDirectories(accessToken: string): Promise<Tenant[]> {
|
||||||
headers.append("Authorization", bearer);
|
headers.append("Authorization", bearer);
|
||||||
|
|
||||||
let tenents: Array<Tenant> = [];
|
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) {
|
while (nextLink) {
|
||||||
const response = await fetch(nextLink, { headers });
|
const response = await fetch(nextLink, { headers });
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { configContext } from "../ConfigContext";
|
||||||
|
|
||||||
export async function fetchPhoto(accessToken: string): Promise<Blob | void> {
|
export async function fetchPhoto(accessToken: string): Promise<Blob | void> {
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
|
@ -12,7 +13,7 @@ export async function fetchPhoto(accessToken: string): Promise<Blob | void> {
|
||||||
headers: headers,
|
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()
|
response.blob()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
import { configContext } from "../ConfigContext";
|
||||||
import { Subscription } from "../Contracts/DataModels";
|
import { Subscription } from "../Contracts/DataModels";
|
||||||
|
|
||||||
interface SubscriptionListResult {
|
interface SubscriptionListResult {
|
||||||
|
@ -13,7 +14,7 @@ export async function fetchSubscriptions(accessToken: string): Promise<Subscript
|
||||||
headers.append("Authorization", bearer);
|
headers.append("Authorization", bearer);
|
||||||
|
|
||||||
let subscriptions: Array<Subscription> = [];
|
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) {
|
while (nextLink) {
|
||||||
const response = await fetch(nextLink, { headers });
|
const response = await fetch(nextLink, { headers });
|
||||||
|
|
Loading…
Reference in New Issue