Skip to content

Commit

Permalink
Merge pull request #784 from OfficeDev/dasau-msal-315
Browse files Browse the repository at this point in the history
Upgrade msal-browser to 3.15.0
  • Loading branch information
codexeon authored May 29, 2024
2 parents d048b02 + b88dbed commit 0063111
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
8 changes: 4 additions & 4 deletions Samples/auth/Outlook-Add-in-SSO-NAA/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Samples/auth/Outlook-Add-in-SSO-NAA/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"watch": "webpack --mode development --watch"
},
"dependencies": {
"@azure/msal-browser": "^3.14.0",
"@azure/msal-browser": "^3.15.0",
"core-js": "^3.9.1",
"regenerator-runtime": "^0.13.7"
},
Expand Down
32 changes: 13 additions & 19 deletions Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/authConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import {
type AccountInfo,
PublicClientNext,
createNestablePublicClientApplication,
type IPublicClientApplication,
Configuration,
LogLevel,
Expand All @@ -29,7 +29,6 @@ function getMsalConfig(enableDebugLogging: boolean) {
auth: {
clientId: applicationId,
authority: "https://login.microsoftonline.com/common",
supportsNestedAppAuth: true,
},
system: {},
};
Expand Down Expand Up @@ -67,18 +66,23 @@ class AccountManager {
// Initialize MSAL public client application.
async initialize() {
// If auth is not working, enable debug logging to help diagnose.
this.pca = await PublicClientNext.createPublicClientApplication(getMsalConfig(false));
this.pca = await createNestablePublicClientApplication(getMsalConfig(false));

// Initialize account by matching account known by Outlook with MSAL.js
let username = "";
let tenantId = "";
let localAccountId = "";
try {
const authContext: AuthContext = await Office.auth.getAuthContext();
username = authContext.userPrincipalName;
tenantId = authContext.tenantId;
localAccountId = authContext.userObjectId;
const username = authContext.userPrincipalName;
const tenantId = authContext.tenantId;
const localAccountId = authContext.userObjectId;
this.loginHint = authContext.loginHint || authContext.userPrincipalName;
const account = this.pca.getAccount({
username,
localAccountId,
tenantId,
});
if (account) {
this.account = account;
}
} catch {
// Intentionally empty catch block.
}
Expand All @@ -90,16 +94,6 @@ class AccountManager {
? Office.context.mailbox.userProfile.emailAddress
: "";
}

// Try to use auth context to find account
this.account = this.pca.getAllAccounts().find((account) => {
return (
(localAccountId && account.localAccountId?.toLowerCase() === localAccountId.toLowerCase()) ||
(account.username &&
account.username === username.toLowerCase() &&
account.tenantId?.toLowerCase() === tenantId)
);
});
}

/**
Expand Down

0 comments on commit 0063111

Please sign in to comment.