mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 23:16:56 +00:00
Use customer endpoint for RBAC AAD auth (#818)
This commit is contained in:
parent
35f8fa8324
commit
2fda881770
@ -1,5 +1,5 @@
|
|||||||
import { useBoolean } from "@fluentui/react-hooks";
|
|
||||||
import { initializeIcons } from "@fluentui/react";
|
import { initializeIcons } from "@fluentui/react";
|
||||||
|
import { useBoolean } from "@fluentui/react-hooks";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { render } from "react-dom";
|
import { render } from "react-dom";
|
||||||
import ChevronRight from "../images/chevron-right.svg";
|
import ChevronRight from "../images/chevron-right.svg";
|
||||||
@ -7,7 +7,7 @@ import "../less/hostedexplorer.less";
|
|||||||
import { AuthType } from "./AuthType";
|
import { AuthType } from "./AuthType";
|
||||||
import { DatabaseAccount } from "./Contracts/DataModels";
|
import { DatabaseAccount } from "./Contracts/DataModels";
|
||||||
import "./Explorer/Menus/NavBar/MeControlComponent.less";
|
import "./Explorer/Menus/NavBar/MeControlComponent.less";
|
||||||
import { useAADAuth } from "./hooks/useAADAuth";
|
import { useAADAuth, useAADDataPlane } from "./hooks/useAADAuth";
|
||||||
import { useTokenMetadata } from "./hooks/usePortalAccessToken";
|
import { useTokenMetadata } from "./hooks/usePortalAccessToken";
|
||||||
import { HostedExplorerChildFrame } from "./HostedExplorerChildFrame";
|
import { HostedExplorerChildFrame } from "./HostedExplorerChildFrame";
|
||||||
import { AccountSwitcher } from "./Platform/Hosted/Components/AccountSwitcher";
|
import { AccountSwitcher } from "./Platform/Hosted/Components/AccountSwitcher";
|
||||||
@ -31,8 +31,9 @@ const App: React.FunctionComponent = () => {
|
|||||||
// For showing/hiding panel
|
// For showing/hiding panel
|
||||||
const [isOpen, { setTrue: openPanel, setFalse: dismissPanel }] = useBoolean(false);
|
const [isOpen, { setTrue: openPanel, setFalse: dismissPanel }] = useBoolean(false);
|
||||||
|
|
||||||
const { isLoggedIn, armToken, graphToken, aadToken, account, tenantId, logout, login, switchTenant } = useAADAuth();
|
const { isLoggedIn, armToken, graphToken, account, tenantId, logout, login, switchTenant } = useAADAuth();
|
||||||
const [databaseAccount, setDatabaseAccount] = React.useState<DatabaseAccount>();
|
const [databaseAccount, setDatabaseAccount] = React.useState<DatabaseAccount>();
|
||||||
|
const { aadToken } = useAADDataPlane(databaseAccount);
|
||||||
const [authType, setAuthType] = React.useState<AuthType>(encryptedToken ? AuthType.EncryptedToken : undefined);
|
const [authType, setAuthType] = React.useState<AuthType>(encryptedToken ? AuthType.EncryptedToken : undefined);
|
||||||
const [connectionString, setConnectionString] = React.useState<string>();
|
const [connectionString, setConnectionString] = React.useState<string>();
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as msal from "@azure/msal-browser";
|
import * as msal from "@azure/msal-browser";
|
||||||
import { useBoolean } from "@fluentui/react-hooks";
|
import { useBoolean } from "@fluentui/react-hooks";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
import { DatabaseAccount } from "../Contracts/DataModels";
|
||||||
|
|
||||||
const config: msal.Configuration = {
|
const config: msal.Configuration = {
|
||||||
cache: {
|
cache: {
|
||||||
@ -104,3 +105,22 @@ export function useAADAuth(): ReturnType {
|
|||||||
switchTenant,
|
switchTenant,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useAADDataPlane(databaseAccount: DatabaseAccount): { aadToken: string } {
|
||||||
|
const [aadToken, setAadToken] = React.useState<string>();
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (databaseAccount?.properties?.documentEndpoint) {
|
||||||
|
const hrefEndpoint = new URL(databaseAccount.properties.documentEndpoint).href.replace(/\/$/, "/.default");
|
||||||
|
msalInstance
|
||||||
|
.acquireTokenSilent({
|
||||||
|
scopes: [hrefEndpoint],
|
||||||
|
})
|
||||||
|
.then((aadTokenResponse) => {
|
||||||
|
setAadToken(aadTokenResponse.accessToken);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [databaseAccount]);
|
||||||
|
|
||||||
|
return { aadToken };
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user