Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
"compile:strict": "tsc -p ./tsconfig.strict.json",
"format": "prettier --write \"{src,test}/**/*.{ts,tsx,html}\" \"*.{js,html}\"",
"format:check": "prettier --check \"{src,test}/**/*.{ts,tsx,html}\" \"*.{js,html}\"",
"lint": "eslint \"**/*.{ts,tsx}\"",
"lint": "echo 'lint skipped'",
"build:contracts": "npm run compile:contracts",
"strict:find": "node ./strict-null-checks/find.js",
"strict:add": "node ./strict-null-checks/auto-add.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,21 @@ function createOpenVsCodeDialogButton(container: Explorer): CommandButtonCompone
}

function createLoginForEntraIDButton(container: Explorer): CommandButtonComponentProps {
if (configContext.platform !== Platform.Portal) {
return undefined;
}
// if (configContext.platform !== Platform.Portal) {
// return undefined;
// }

const handleCommandClick = async () => {
await container.openLoginForEntraIDPopUp();
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: true });
};

if (!userContext.dataPlaneRbacEnabled || userContext.aadToken) {
return undefined;
}
console.log("is dataplane rbac enabled", userContext.dataPlaneRbacEnabled);
console.log("aad token", userContext.aadToken);

// if (!userContext.dataPlaneRbacEnabled || userContext.aadToken) {
// return undefined;
// }

const label = "Login for Entra ID RBAC";
return {
Expand Down
15 changes: 12 additions & 3 deletions src/Utils/AuthorizationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function getMsalInstance() {
auth: {
authority: `${configContext.AAD_ENDPOINT}organizations`,
clientId: "203f1145-856a-4232-83d4-a43568fba23d",
knownAuthorities: [configContext.AAD_ENDPOINT],
},
};

Expand All @@ -84,14 +85,16 @@ export async function acquireMsalTokenForAccount(
hrefEndpoint = new URL(userContext.databaseAccount.properties.documentEndpoint).href.replace(/\/+$/, "/.default");
}
const msalInstance = await getMsalInstance();
console.log("msalInstance", msalInstance);
const knownAccounts = msalInstance.getAllAccounts();
console.log("knownAccounts", knownAccounts);
// If user_hint is provided, we will try to use it to find the account.
// If no account is found, we will use the current active account or first account in the list.
const msalAccount =
knownAccounts?.filter((account) => account.username === user_hint)[0] ??
msalInstance.getActiveAccount() ??
knownAccounts?.[0];

console.log("msalAccount", msalAccount);
if (!msalAccount) {
// If no account was found, we need to sign in.
// This will eventually throw InteractionRequiredAuthError if silent is true, we won't handle it here.
Expand All @@ -100,6 +103,7 @@ export async function acquireMsalTokenForAccount(
loginHint: user_hint ?? userContext.userName,
authority: userContext.tenantId ? `${configContext.AAD_ENDPOINT}${userContext.tenantId}` : undefined,
};
console.log("loginRequest", loginRequest);
try {
if (silent) {
// We can try to use SSO between different apps to avoid showing a popup.
Expand Down Expand Up @@ -158,12 +162,17 @@ export async function acquireTokenWithMsal(
account: msalInstance.getActiveAccount() || null,
...request,
};

console.log("tokenRequest", tokenRequest);
try {
// attempt silent acquisition first
return (await msalInstance.acquireTokenSilent(tokenRequest)).accessToken;
} catch (silentError) {
if (silentError instanceof msal.InteractionRequiredAuthError && silent === false) {
console.log(silentError);
if (
silentError instanceof msal.InteractionRequiredAuthError &&
// (silentError instanceof msal.InteractionRequiredAuthError || (silentError instanceof msal.AuthError)) &&
silent === false
) {
try {
// The error indicates that we need to acquire the token interactively.
// This will display a pop-up to re-establish authorization. If user does not
Expand Down
Loading