From 78aa37e21de4a18d3b7bcd2b9f157fe91b84ef21 Mon Sep 17 00:00:00 2001 From: Dan Saunders Date: Tue, 28 May 2024 22:20:01 -0700 Subject: [PATCH 1/2] upgrade msal-browser to 3.15 --- .../Outlook-Add-in-SSO-NAA/package-lock.json | 8 ++--- .../auth/Outlook-Add-in-SSO-NAA/package.json | 2 +- .../src/taskpane/authConfig.ts | 31 ++++++++----------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Samples/auth/Outlook-Add-in-SSO-NAA/package-lock.json b/Samples/auth/Outlook-Add-in-SSO-NAA/package-lock.json index 58d8f4a79..3bcf83fcd 100644 --- a/Samples/auth/Outlook-Add-in-SSO-NAA/package-lock.json +++ b/Samples/auth/Outlook-Add-in-SSO-NAA/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "license": "MIT", "dependencies": { - "@azure/msal-browser": "^3.14.0", + "@azure/msal-browser": "^3.15.0", "core-js": "^3.9.1", "regenerator-runtime": "^0.13.7" }, @@ -509,9 +509,9 @@ } }, "node_modules/@azure/msal-browser": { - "version": "3.14.0", - "resolved": "https://registry.npmjs.org/@azure/msal-browser/-/msal-browser-3.14.0.tgz", - "integrity": "sha512-Un85LhOoecJ3HDTS3Uv3UWnXC9/43ZSO+Kc+anSqpZvcEt58SiO/3DuVCAe1A3I5UIBYJNMgTmZPGXQ0MVYrwA==", + "version": "3.15.0", + "resolved": "https://registry.npmjs.org/@azure/msal-browser/-/msal-browser-3.15.0.tgz", + "integrity": "sha512-jqngIR0zGLtEHCAhgXLl+VZTFcU/9DmRSjGj5RbrLnFPL/0L9Hr68k8grvLrTIq7tjhTM5Xgh6Xc0l7JlViHQQ==", "dependencies": { "@azure/msal-common": "14.10.0" }, diff --git a/Samples/auth/Outlook-Add-in-SSO-NAA/package.json b/Samples/auth/Outlook-Add-in-SSO-NAA/package.json index 988f15c32..3cff98d6c 100644 --- a/Samples/auth/Outlook-Add-in-SSO-NAA/package.json +++ b/Samples/auth/Outlook-Add-in-SSO-NAA/package.json @@ -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" }, diff --git a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/authConfig.ts b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/authConfig.ts index 00981a0c6..ee08870f6 100644 --- a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/authConfig.ts +++ b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/authConfig.ts @@ -7,7 +7,7 @@ import { type AccountInfo, - PublicClientNext, + createNestablePublicClientApplication, type IPublicClientApplication, Configuration, LogLevel, @@ -67,18 +67,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. } @@ -90,16 +95,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) - ); - }); } /** From b88dbed8629fabf6e0137560f62f6e6a2418c5dd Mon Sep 17 00:00:00 2001 From: Dan Saunders Date: Wed, 29 May 2024 12:51:25 -0700 Subject: [PATCH 2/2] remove supportsNestedAppAuth config property --- Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/authConfig.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/authConfig.ts b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/authConfig.ts index ee08870f6..37fe0ec17 100644 --- a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/authConfig.ts +++ b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/authConfig.ts @@ -29,7 +29,6 @@ function getMsalConfig(enableDebugLogging: boolean) { auth: { clientId: applicationId, authority: "https://login.microsoftonline.com/common", - supportsNestedAppAuth: true, }, system: {}, };