mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-05-15 09:47:30 +01:00
Fix MPAC redirect URL (#2456)
* Fix MPAC redirect URL * Address comment
This commit is contained in:
@@ -163,4 +163,42 @@ describe("AuthorizationUtils", () => {
|
||||
expect((instance as any)._config.auth.redirectUri).toBe("http://localhost/redirectBridge.html");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getRedirectBridgeUrl()", () => {
|
||||
const originalNodeEnv = process.env.NODE_ENV;
|
||||
const originalPathname = window.location.pathname;
|
||||
|
||||
afterEach(() => {
|
||||
process.env.NODE_ENV = originalNodeEnv;
|
||||
Object.defineProperty(window, "location", {
|
||||
value: { ...window.location, pathname: originalPathname },
|
||||
writable: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("should use dev URL in development mode", () => {
|
||||
process.env.NODE_ENV = "development";
|
||||
expect(AuthorizationUtils.getRedirectBridgeUrl()).toBe(
|
||||
"https://dataexplorer-dev.azurewebsites.net/redirectBridge.html",
|
||||
);
|
||||
});
|
||||
|
||||
it("should use MPAC path when on /mpac/", () => {
|
||||
process.env.NODE_ENV = "production";
|
||||
Object.defineProperty(window, "location", {
|
||||
value: { origin: "https://cosmos.azure.com", pathname: "/mpac/explorer.html" },
|
||||
writable: true,
|
||||
});
|
||||
expect(AuthorizationUtils.getRedirectBridgeUrl()).toBe("https://cosmos.azure.com/mpac/redirectBridge.html");
|
||||
});
|
||||
|
||||
it("should use root path when not on /mpac/", () => {
|
||||
process.env.NODE_ENV = "production";
|
||||
Object.defineProperty(window, "location", {
|
||||
value: { origin: "https://cosmos.azure.com", pathname: "/explorer.html" },
|
||||
writable: true,
|
||||
});
|
||||
expect(AuthorizationUtils.getRedirectBridgeUrl()).toBe("https://cosmos.azure.com/redirectBridge.html");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,12 +50,25 @@ export function decryptJWTToken(token: string) {
|
||||
return JSON.parse(tokenPayload);
|
||||
}
|
||||
|
||||
export function getRedirectBridgeUrl(): string {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
return "https://dataexplorer-dev.azurewebsites.net/redirectBridge.html";
|
||||
}
|
||||
const basePath = window.location.pathname.startsWith("/mpac/") ? "/mpac" : "";
|
||||
return `${window.location.origin}${basePath}/redirectBridge.html`;
|
||||
}
|
||||
|
||||
export function getPostLogoutRedirectUrl(): string {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
return "https://dataexplorer-dev.azurewebsites.net/hostedExplorer.html";
|
||||
}
|
||||
const basePath = window.location.pathname.startsWith("/mpac/") ? "/mpac" : "";
|
||||
return `${window.location.origin}${basePath}`;
|
||||
}
|
||||
|
||||
export async function getMsalInstance() {
|
||||
// Compute the redirect bridge URL for MSAL v5 COOP handling
|
||||
const redirectBridgeUrl =
|
||||
process.env.NODE_ENV === "development"
|
||||
? "https://dataexplorer-dev.azurewebsites.net/redirectBridge.html"
|
||||
: `${window.location.origin}/redirectBridge.html`;
|
||||
const redirectBridgeUrl = getRedirectBridgeUrl();
|
||||
|
||||
const msalConfig: msal.Configuration = {
|
||||
cache: {
|
||||
|
||||
Reference in New Issue
Block a user