From 02e64001b4fb578709074396ee8517f66ecae4c0 Mon Sep 17 00:00:00 2001 From: Dan Saunders Date: Tue, 8 Oct 2024 15:46:48 -0700 Subject: [PATCH] [Outlook] - Update Outlook NAA sample to use standard public client as fallback. (#866) * use standard public client application in fallback path * Update Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/fallbackauthdialog.ts Co-authored-by: Alex Jerabek <38896772+AlexJerabek@users.noreply.github.com> * Update Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/dialog.html Co-authored-by: Alex Jerabek <38896772+AlexJerabek@users.noreply.github.com> * Update Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/taskpane.html Co-authored-by: Alex Jerabek <38896772+AlexJerabek@users.noreply.github.com> --------- Co-authored-by: Alex Jerabek <38896772+AlexJerabek@users.noreply.github.com> --- .../src/taskpane/fallback/dialog.html | 2 +- .../taskpane/fallback/fallbackauthdialog.ts | 13 ++++++---- .../src/taskpane/fallback/signoutdialog.ts | 24 ------------------- .../src/taskpane/taskpane.html | 2 +- .../Outlook-Add-in-SSO-NAA/webpack.config.js | 6 ----- 5 files changed, 11 insertions(+), 36 deletions(-) delete mode 100644 Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/signoutdialog.ts diff --git a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/dialog.html b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/dialog.html index a5e29ed1..2cc53034 100644 --- a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/dialog.html +++ b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/dialog.html @@ -10,7 +10,7 @@ Dialog - + diff --git a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/fallbackauthdialog.ts b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/fallbackauthdialog.ts index a43f4027..0d478896 100644 --- a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/fallbackauthdialog.ts +++ b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/fallbackauthdialog.ts @@ -5,10 +5,14 @@ /* global Office, window, URLSearchParams */ -import { AuthenticationResult, IPublicClientApplication } from "@azure/msal-browser"; -import { getTokenRequest, ensurePublicClient } from "../msalcommon"; +import { + AuthenticationResult, + createStandardPublicClientApplication, + IPublicClientApplication, +} from "@azure/msal-browser"; +import { getTokenRequest } from "../msalcommon"; import { createLocalUrl } from "../util"; -import { defaultScopes } from "../msalconfig"; +import { defaultScopes, msalConfig } from "../msalconfig"; import type { AuthDialogResult } from "../authConfig"; // read querystring parameter @@ -32,7 +36,8 @@ async function returnResult(publicClientApp: IPublicClientApplication, authResul } export async function initializeMsal() { - const publicClientApp = await ensurePublicClient(); + // Use standard Public Client instead of nested because this is a fallback path when nested app authentication isn't available. + const publicClientApp = await createStandardPublicClientApplication(msalConfig); try { if (getQueryParameter("logout") === "1") { await publicClientApp.logoutRedirect({ postLogoutRedirectUri: createLocalUrl("dialog.html?close=1") }); diff --git a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/signoutdialog.ts b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/signoutdialog.ts deleted file mode 100644 index 0bf0e47d..00000000 --- a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/fallback/signoutdialog.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -// This file handles the sign out dialog for MSAL V3. - -/* global Office */ - -import { PublicClientApplication } from "@azure/msal-browser"; -import { msalConfig } from "../msalconfig"; - -export async function initializeMsal() { - const publicClientApp = new PublicClientApplication(msalConfig); - try { - await publicClientApp.logoutRedirect(); - await Office.onReady(); - Office.context.ui.messageParent(JSON.stringify({ status: "success" })); - return; - } catch (ex) { - await Office.onReady(); - Office.context.ui.messageParent(JSON.stringify({ error: ex.name })); - return; - } -} -initializeMsal(); diff --git a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/taskpane.html b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/taskpane.html index c2faa830..0f4ac541 100644 --- a/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/taskpane.html +++ b/Samples/auth/Outlook-Add-in-SSO-NAA/src/taskpane/taskpane.html @@ -10,7 +10,7 @@ Contoso Task Pane Add-in - + { polyfill: ["core-js/stable", "regenerator-runtime/runtime"], taskpane: ["./src/taskpane/taskpane.ts", "./src/taskpane/taskpane.html"], dialog: ["./src/taskpane/fallback/fallbackauthdialog.ts"], - signoutdialog: ["./src/taskpane/fallback/signoutdialog.ts"], }, output: { clean: true, @@ -70,11 +69,6 @@ module.exports = async (env, options) => { template: "./src/taskpane/fallback/dialog.html", chunks: ["dialog"], }), - new HtmlWebpackPlugin({ - filename: "signoutdialog.html", - template: "./src/taskpane/fallback/dialog.html", - chunks: ["signoutdialog"], - }), new CopyWebpackPlugin({ patterns: [ {