Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Outlook](NAA) Sample showing how to pass user identity to network resource #924

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

davidchesnut
Copy link
Member

Q A
Bug fix? no
New feature? no
New sample? yes
Related issues? NA

What's in this Pull Request?

Shows how to properly handle the identity token and claims in an Outlook task pane add-in (SPA). Replaces the old Exchange token pattern of sending id token to the server API. Instead you use the access token which contains the identity claims for the server to manage a todo database.

Copy link
Collaborator

@AlexJerabek AlexJerabek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went until I got stuck. Please let me know what I'm missing for the Entra admin center.

- Set **Supported account types** to **Accounts in this organizational directory only**.
- Select **Register**.

1. In the app's registration screen, select the **Expose an API** blade to the left to open the page where you can publish the permission as an API for which client applications can obtain access tokens for. The first thing that we need to do is to declare the unique resource URI that the clients will be using to obtain access tokens for this API. To declare an resource URI(Application ID URI), follow the following steps:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was under a submenu for me.

image

Open the sample project in Visual Studio Code to configure the code. In the steps below, "ClientID" is the same as "Application ID" or "AppId".

1. Open the API/server-helpers/authConfig.js file.
1. Find the key `Enter_API_Application_Id_Here` and replace the existing value with the application ID (clientId) of Contoso-Web-API-Server app copied from the Microsoft Entra admin center.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When did I go to the Microsoft Entra admin center and register something?

Samples/auth/Outlook-Add-in-SSO-NAA-Identity/README.md Outdated Show resolved Hide resolved
Samples/auth/Outlook-Add-in-SSO-NAA-Identity/README.md Outdated Show resolved Hide resolved

All APIs must publish a minimum of one scope, also called Delegated Permission, for the client apps to obtain an access token for a user successfully. To publish a scope, follow these steps:

1. Select **Add a scope** button open the **Add a scope** screen and Enter the values as indicated below:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list and the next one have different numbering styles. Let's pick one to be consistent.

Also, consider making the "Repeat" step, Step 2. It'll make it more obvious that's an action, instead of informatino text.

davidchesnut and others added 4 commits January 27, 2025 15:44
Co-authored-by: Linda Cannon <[email protected]>
Co-authored-by: Alex Jerabek <[email protected]>
Comment on lines +110 to +113
1. In the **Redirect URI** section, enter the following redirect URIs:
1. `http://localhost:3000`
1. `http://localhost:3000/redirect`
1. `brk-multihub://localhost:3000`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you enter multiple redirects into this field?

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so the confusing part to me is that you enter one of these in the setup screen (as shown above), then add two additional URIs through a different interface (as in the screenshot below). The readme makes it seem like you can complete this in one fell swoop.

image

Copy link
Member

@lindalu-MSFT lindalu-MSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

1. The Outlook add-in (SPA client) uses the MSAL.js library to obtain an access token from Microsoft Entra ID. The MSAL.js library returns an ID token, access token, and refresh token.
1. The access token is passed in a web request to a protected web API service. The web request validates the access token and confirms the user has permissions to perform the action in the API. The access token contains any identity claims the web API needs.

![A diagram showing the Outlook add-in getting an access token from Microsoft Entra ID and calling the protected web API with the access token.](architecture-diagram.png)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
![A diagram showing the Outlook add-in getting an access token from Microsoft Entra ID and calling the protected web API with the access token.](architecture-diagram.png)
![A diagram showing the Outlook add-in getting an access token from Microsoft Entra ID and calling the protected web API with the access token.](./images/architecture-diagram.png)

Comment on lines +110 to +113
1. In the **Redirect URI** section, enter the following redirect URIs:
1. `http://localhost:3000`
1. `http://localhost:3000/redirect`
1. `brk-multihub://localhost:3000`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so the confusing part to me is that you enter one of these in the setup screen (as shown above), then add two additional URIs through a different interface (as in the screenshot below). The readme makes it seem like you can complete this in one fell swoop.

image


Your scopes should appear as shown in the following screenshot.

![list of scopes](./images/scopes-added-client.png)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This screenshot should be under step 4, since the reader has already moved on from this pane in the app registrations.


```console
cd API
npm install
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, these install commands are already generating high vulnerability warnings.

npm start
```

The following instructions assume you are sideloading in Outlook for Windows. To sideload on other platforms, see [Sideload Outlook add-ins for testing](https://learn.microsoft.com/office/dev/add-ins/outlook/sideload-outlook-add-ins-for-testing)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following instructions don't talk about sideloading - they assume you've already sideloaded.

- Set **Name** to `Contoso-Web-API-Server`.
- Set **Supported account types** to **Accounts in this organizational directory only**.
- Select **Register**.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second time we register an application here, we are told to note the Application (client) ID. For this first application, we are told to grab the ID from the Microsoft Entra admin center when needed. I'd recommend avoiding sending people to the other admin center (unless that's what I'm messing up).


1. In the **Overview** blade, find and note the **Application (client) ID**. You use this value in your app's configuration file(s) later in your code.
1. In the app's registration screen, select the **Authentication** blade on the left pane.
1. If you don't have a platform added, select **Add a platform** and choose the **Single-page application** option.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you have a platform added at this point in the sample?

Comment on lines +188 to +189
1. In the task pane, enter a new task in the text box, and select **Add**. You can enter multiple tasks.
1. Select **Get todo list** to get the task list.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting this error after signing in. FWIW, on the first write attempt, I didn't check "Consent on behalf of the organization" and haven't been reprompted to do so.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants