diff --git a/Samples/auth/Outlook-Event-SSO-NAA/.eslintrc.json b/Samples/auth/Outlook-Event-SSO-NAA/.eslintrc.json new file mode 100644 index 000000000..e406c09e8 --- /dev/null +++ b/Samples/auth/Outlook-Event-SSO-NAA/.eslintrc.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + "office-addins" + ], + "extends": [ + "plugin:office-addins/recommended" + ] +} diff --git a/Samples/auth/Outlook-Event-SSO-NAA/.gitignore b/Samples/auth/Outlook-Event-SSO-NAA/.gitignore new file mode 100644 index 000000000..6a7d6d8ef --- /dev/null +++ b/Samples/auth/Outlook-Event-SSO-NAA/.gitignore @@ -0,0 +1,130 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* \ No newline at end of file diff --git a/Samples/auth/Outlook-Event-SSO-NAA/.vscode/extensions.json b/Samples/auth/Outlook-Event-SSO-NAA/.vscode/extensions.json new file mode 100644 index 000000000..c5fccff07 --- /dev/null +++ b/Samples/auth/Outlook-Event-SSO-NAA/.vscode/extensions.json @@ -0,0 +1,13 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "ms-edgedevtools.vscode-edge-devtools", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [] +} diff --git a/Samples/auth/Outlook-Event-SSO-NAA/.vscode/launch.json b/Samples/auth/Outlook-Event-SSO-NAA/.vscode/launch.json new file mode 100644 index 000000000..db9261534 --- /dev/null +++ b/Samples/auth/Outlook-Event-SSO-NAA/.vscode/launch.json @@ -0,0 +1,34 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Direct Debugging", + "type": "node", + "request": "attach", + "port": 9223, + "timeout": 600000, + "trace": true + }, + { + "name": "Outlook Desktop (Edge Chromium)", + "type": "msedge", + "request": "attach", + "port": 9229, + "timeout": 600000, + "webRoot": "${workspaceRoot}", + "preLaunchTask": "Debug: Outlook Desktop", + "postDebugTask": "Stop Debug" + }, + { + "name": "Outlook Desktop (Edge Legacy)", + "type": "office-addin", + "request": "attach", + "url": "https://localhost:3000/taskpane.html?_host_Info=Outlook$Win32$16.01$en-US$$$$0", + "port": 9222, + "timeout": 600000, + "webRoot": "${workspaceRoot}", + "preLaunchTask": "Debug: Outlook Desktop", + "postDebugTask": "Stop Debug" + } + ] +} \ No newline at end of file diff --git a/Samples/auth/Outlook-Event-SSO-NAA/.vscode/settings.json b/Samples/auth/Outlook-Event-SSO-NAA/.vscode/settings.json new file mode 100644 index 000000000..5dec57b1d --- /dev/null +++ b/Samples/auth/Outlook-Event-SSO-NAA/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "eslint.validate": [ + "javascript", + "javascriptreact", + "typescript" + ] + } + \ No newline at end of file diff --git a/Samples/auth/Outlook-Event-SSO-NAA/.vscode/tasks.json b/Samples/auth/Outlook-Event-SSO-NAA/.vscode/tasks.json new file mode 100644 index 000000000..642b3d7bd --- /dev/null +++ b/Samples/auth/Outlook-Event-SSO-NAA/.vscode/tasks.json @@ -0,0 +1,156 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build (Development)", + "type": "npm", + "script": "build:dev", + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "clear": true, + "panel": "shared", + "showReuseMessage": false + } + }, + { + "label": "Build (Production)", + "type": "npm", + "script": "build", + "group": "build", + "presentation": { + "clear": true, + "panel": "shared", + "showReuseMessage": false + } + }, + { + "label": "Debug: Excel Desktop", + "type": "shell", + "command": "npm", + "args": [ + "run", + "start:desktop", + "--", + "--app", + "excel" + ], + "presentation": { + "clear": true, + "panel": "dedicated" + }, + "problemMatcher": [] + }, + { + "label": "Debug: Outlook Desktop", + "type": "shell", + "command": "npm", + "args": [ + "run", + "start:desktop", + "--", + "--app", + "outlook" + ], + "presentation": { + "clear": true, + "panel": "dedicated" + }, + "problemMatcher": [] + }, + { + "label": "Debug: PowerPoint Desktop", + "type": "shell", + "command": "npm", + "args": [ + "run", + "start:desktop", + "--", + "--app", + "powerpoint" + ], + "presentation": { + "clear": true, + "panel": "dedicated" + }, + "problemMatcher": [] + }, + { + "label": "Debug: Word Desktop", + "type": "shell", + "command": "npm", + "args": [ + "run", + "start:desktop", + "--", + "--app", + "word" + ], + "presentation": { + "clear": true, + "panel": "dedicated" + }, + "problemMatcher": [] + }, + { + "label": "Dev Server", + "type": "npm", + "script": "dev-server", + "presentation": { + "clear": true, + "panel": "dedicated" + }, + "problemMatcher": [] + }, + { + "label": "Install", + "type": "npm", + "script": "install", + "presentation": { + "clear": true, + "panel": "shared", + "showReuseMessage": false + }, + "problemMatcher": [] + }, + { + "label": "Lint: Check for problems", + "type": "npm", + "script": "lint", + "problemMatcher": [ + "$eslint-stylish" + ] + }, + { + "label": "Lint: Fix all auto-fixable problems", + "type": "npm", + "script": "lint:fix", + "problemMatcher": [ + "$eslint-stylish" + ] + }, + { + "label": "Stop Debug", + "type": "npm", + "script": "stop", + "presentation": { + "clear": true, + "panel": "shared", + "showReuseMessage": false + }, + "problemMatcher": [] + }, + { + "label": "Watch", + "type": "npm", + "script": "watch", + "presentation": { + "clear": true, + "panel": "dedicated" + }, + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/Samples/auth/Outlook-Event-SSO-NAA/README.md b/Samples/auth/Outlook-Event-SSO-NAA/README.md new file mode 100644 index 000000000..b7911dc29 --- /dev/null +++ b/Samples/auth/Outlook-Event-SSO-NAA/README.md @@ -0,0 +1,135 @@ +--- +page_type: sample +urlFragment: outlook-event-sso-naa +products: + - office + - office-outlook +languages: + - javascript +extensions: + contentType: samples + technologies: + - Add-ins + createdDate: "08/20/2024 10:00:00 AM" +description: "This sample shows how to implement SSO in an event in an Outlook add-in by using nested app authentication." +--- + +# Implement SSO in events in an Outlook add-in using nested app authentication (preview) + +## Summary + +This sample demonstrates how to use single sign-on (SSO) in an Outlook add-in event using the Microsoft Authentication Library for JavaScript (MSAL.js) and nested app authentication (NAA) to access Microsoft Graph APIs for the authenticated user. The sample displays the signed-in user's name as a signature in the body of a new email or calendar item. + +> [!IMPORTANT] +> Nested app authentication is currently in preview. To try this feature, join the [Microsoft 365 Insider Program](https://insider.microsoft365.com/join) and choose **Beta Channel**. Don't use NAA in production add-ins. We invite you to try out NAA in test or development environments and welcome feedback on your experience through GitHub (see https://github.com/OfficeDev/office-js/issues). + +## Features + +- Use MSAL.js NAA to get an access token for the signed in user to call Microsoft Graph APIs. +- Get an access token through NAA in the `OnNewMessageCompose` and `OnNewAppointmentOrganizer` events. +- Add a signature to an email or calendar invite with the signed-in user's name. + +## Applies to + +- Outlook (Beta Channel for classic Outlook only, new Outlook coming soon). +- Outlook on the web. + +For more information on supported platforms, see [NAA supported accounts and hosts](https://learn.microsoft.com/office/dev/add-ins/develop/enable-nested-app-authentication-in-your-add-in#naa-supported-accounts-and-hosts). + +## Prerequisites + +- Office connected to a Microsoft 365 subscription (including Office on the web). +- You need to join the [Microsoft 365 Insider Program](https://insider.microsoft365.com/join) to use the NAA preview features. Choose the **Beta Channel** insider level. +- [Node.js](https://nodejs.org/) version 16 or greater. +- [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) version 8 or greater. + +## Build and run the solution + +### Create an application registration + +1. Go to the [Azure portal - App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page to register your app. +1. Sign in with the ***admin*** credentials to your Microsoft 365 tenancy. For example, **MyName@contoso.onmicrosoft.com**. +1. Select **New registration**. On the **Register an application** page, set the values as follows. + + - Set **Name** to `Outlook-Event-SSO-NAA`. + - Set **Supported account types** to **Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)**. + - In the **Redirect URI** section, ensure that **Single-page application (SPA)** is selected in the drop down and then set the URI to `brk-multihub://localhost:3000`. + - Select **Register**. + +1. On the **Outlook-Add-in-SSO-NAA** page, copy and save the value for the **Application (client) ID**. You'll use it in the next section. + +For more information on how to register your application, see [Register an application with the Microsoft Identity Platform](https://learn.microsoft.com/graph/auth-register-app-v2). + +### Configure the sample + +1. Clone or download this repository. +1. From the command line, or a terminal window, go to the root folder of this sample at `/samples/auth/Outlook-Event-SSO-NAA`. +1. Open the `src/launchevent/authconfig.js` file. +1. Replace the placeholder "Enter_the_Application_Id_Here" with the Application ID that you copied. +1. Save the file. + +## Run the sample + +First ensure you're signed in and consent to the add-in's scopes. Once you approve consent, you no longer need to do those steps. + +1. Run the following commands. + + `npm install` + `npm run build:dev` + `npm run start` + + This will start the web server and sideload the add-in to Outlook. + +1. Start Outlook (classic) and sign in. +1. Open an existing email item. +1. Choose "Show Task Pane" from the ribbon. This will open the task pane of the add-in. +1. Select the **Sign in** button to sign in. You may be prompted to consent to the scopes of the add-in. The task pane will indicate it signed in by displaying your user name. + +Now you can use the event-based code. + +1. Create a new email. The add-in will automatically add a signature with your signed in name. + +## Debugging steps + +To debug this sample, follow the instructions in [Debug your event-based or spam-reporting Outlook add-in](https://learn.microsoft.com/office/dev/add-ins/outlook/debug-autolaunch). All `console.log` statements from the event code appear in the [runtime log](https://learn.microsoft.com/office/dev/add-ins/testing/runtime-logging). + +## Key parts of this sample + +### Events using MSAL.js with NAA + +The `src/launchevent/launchevent.js` file contains the code for the Outlook events. It initializes the public client application (PCA) for MSAL and calls `acquireTokenSilent` to get the access token. It does not call `acquireTokenPopup` because event code cannot interact with UI. If `acquiretokenSilent` fails, it will log the error. `console.write` statements will write messages to the [runtime log](https://learn.microsoft.com/office/dev/add-ins/testing/runtime-logging). + +### Webpack configuration and hot reload + +The `webpack.config.js` file is updated from what yo office generates. Hot reload code from webpack is not supported in the JS runtime for Outlook events. The webpack config modifiations ensure you can import the MSAL.js library without the hot reload code. + +### Well-known URI + +The `src/well-known/microsoft-officeaddins-allowed.json` file lists `https://localhost:3000/public/launchevent.js` as an allowed file to access SSO. For more information, see [Use single sign-on (SSO) or cross-origin resource sharing (CORS) in your event-based or spam-reporting Outlook add-in](https://learn.microsoft.com/office/dev/add-ins/outlook/use-sso-in-event-based-activation). + +## Security reporting + +If you find a security issue with our libraries or services, report the issue to [secure@microsoft.com](mailto:secure@microsoft.com) with as much detail as you can provide. Your submission may be eligible for a bounty through the [Microsoft Bounty](https://aka.ms/bugbounty) program. Don't post security issues to [GitHub Issues](https://github.com/AzureAD/microsoft-authentication-library-for-android/issues) or any other public site. We'll contact you shortly after receiving your issue report. We encourage you to get new security incident notifications by visiting [Microsoft technical security notifications](https://technet.microsoft.com/security/dd252948) to subscribe to Security Advisory Alerts. + +## Questions and feedback + +- Did you experience any problems with the sample? [Create an issue](https://github.com/OfficeDev/Office-Add-in-samples/issues/new/choose) and we'll help you out. +- We'd love to get your feedback about this sample. Go to our [Office samples survey](https://aka.ms/OfficeSamplesSurvey) to give feedback and suggest improvements. +- For general questions about developing Office Add-ins, go to [Microsoft Q&A](https://learn.microsoft.com/answers/topics/office-js-dev.html) using the office-js-dev tag. + +## More resources + +- NAA public preview blog: https://aka.ms/NAApreviewblog +- [Updates on deprecating legacy Exchange Online tokens for Outlook add-ins](https://devblogs.microsoft.com/microsoft365dev/updates-on-deprecating-legacy-exchange-online-tokens-for-outlook-add-ins/?commentid=1131) +- NAA docs to get started: https://aka.ms/NAAdocs +- NAA FAQ: https://aka.ms/NAAFAQ +- NAA Outlook sample: https://aka.ms/NAAsampleOutlook +- NAA Word, Excel, and PowerPoint sample: https://aka.ms/NAAsampleOffice + +## Copyright + +Copyright (c) 2024 Microsoft Corporation. All rights reserved. + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information, see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + + \ No newline at end of file diff --git a/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-128.png b/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-128.png new file mode 100644 index 000000000..37dfcd770 Binary files /dev/null and b/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-128.png differ diff --git a/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-16.png b/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-16.png new file mode 100644 index 000000000..b6509798a Binary files /dev/null and b/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-16.png differ diff --git a/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-32.png b/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-32.png new file mode 100644 index 000000000..dcf56db70 Binary files /dev/null and b/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-32.png differ diff --git a/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-64.png b/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-64.png new file mode 100644 index 000000000..41051fce8 Binary files /dev/null and b/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-64.png differ diff --git a/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-80.png b/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-80.png new file mode 100644 index 000000000..5e63769d8 Binary files /dev/null and b/Samples/auth/Outlook-Event-SSO-NAA/assets/icon-80.png differ diff --git a/Samples/auth/Outlook-Event-SSO-NAA/assets/logo-filled.png b/Samples/auth/Outlook-Event-SSO-NAA/assets/logo-filled.png new file mode 100644 index 000000000..5bf09cc24 Binary files /dev/null and b/Samples/auth/Outlook-Event-SSO-NAA/assets/logo-filled.png differ diff --git a/Samples/auth/Outlook-Event-SSO-NAA/assets/sample.json b/Samples/auth/Outlook-Event-SSO-NAA/assets/sample.json new file mode 100644 index 000000000..4ce96574c --- /dev/null +++ b/Samples/auth/Outlook-Event-SSO-NAA/assets/sample.json @@ -0,0 +1,41 @@ +[ + { + "name": "outlook-event-sso-naa", + "reponame": "office-add-in-samples", + "source": "officedev", + "title": "Outlook event-based add-in using SSO with nested app authentication (preview)", + "shortDescription": "This sample shows how to implement SSO in an Outlook event-based add-in.", + "url": "https://github.com/OfficeDev/Office-Add-in-samples/tree/main/Samples/auth/Outlook-Add-in-SSO-NAA", + "longDescription": [ + "This sample shows how to implement SSO in an event in an Outlook add-in by using nested app authentication." + ], + "creationDateTime": "2024-08-21", + "updateDateTime": "2024-08-21", + "products": [ + "Office" + ], + "metadata": [ + { + "key": "CLIENT-SIDE-DEV", + "value": "JavaScript" + } + ], + "thumbnails": [ + + ], + "authors": [ + { + "gitHubAccount": "microsoft", + "pictureUrl": "https://github.com/microsoft.png", + "name": "Microsoft" + } + ], + "references": [ + { + "name": "Use SSO in events in an Outlook add-in using nested app authentication (preview)", + "description": "This sample shows how to implement SSO in an event in an Outlook add-in by using nested app authentication.", + "url": "https://learn.microsoft.com/office/dev/add-ins/develop/enable-nested-app-authentication-in-your-add-in" + } + ] + } + ] \ No newline at end of file diff --git a/Samples/auth/Outlook-Event-SSO-NAA/babel.config.json b/Samples/auth/Outlook-Event-SSO-NAA/babel.config.json new file mode 100644 index 000000000..8aa924d7c --- /dev/null +++ b/Samples/auth/Outlook-Event-SSO-NAA/babel.config.json @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env"] +} \ No newline at end of file diff --git a/Samples/auth/Outlook-Event-SSO-NAA/manifest.xml b/Samples/auth/Outlook-Event-SSO-NAA/manifest.xml new file mode 100644 index 000000000..9cc2644da --- /dev/null +++ b/Samples/auth/Outlook-Event-SSO-NAA/manifest.xml @@ -0,0 +1,144 @@ + + + 16c028c6-f97d-4b09-96eb-3821219e0a47 + 1.0.0.0 + Contoso + en-US + + + + + + + https://www.contoso.com + + + + + + + + + + +
+ + + 250 + +
+
+ ReadWriteMailbox + + + + true + + + + + + + + + + + + + + + + + + + + + + +