mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 09:20:16 +00:00
Use customer endpoint for RBAC AAD auth (#818)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import * as msal from "@azure/msal-browser";
|
||||
import { useBoolean } from "@fluentui/react-hooks";
|
||||
import * as React from "react";
|
||||
import { DatabaseAccount } from "../Contracts/DataModels";
|
||||
|
||||
const config: msal.Configuration = {
|
||||
cache: {
|
||||
@@ -104,3 +105,22 @@ export function useAADAuth(): ReturnType {
|
||||
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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user