Skip to content

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?


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 <lindalu@microsoft.com>
Co-authored-by: Alex Jerabek <38896772+AlexJerabek@users.noreply.github.com>
Co-authored-by: Linda Cannon <lindalu@microsoft.com>
Co-authored-by: Linda Cannon <lindalu@microsoft.com>
Co-authored-by: Linda Cannon <lindalu@microsoft.com>
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!

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.

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

const token = authHeader.split(" ")[1];
req.token = token;
const validationOptions = {
audience: authConfig.credentials.clientID, // v2.0 token
Copy link
Collaborator

Choose a reason for hiding this comment

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

this doesn't seem to be validating issuer. Follow guidelines at https://learn.microsoft.com/en-us/entra/identity-platform/access-tokens#validating-tokens, if this really is a single tenant application you can hardcode the issuer, else you need to include tenant id from the token.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed.

/* global console */

export const clientId = "Enter_Application_Client_Id_Here";
export const msalConfig = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

recommend to specify type as msalConfig: Configuration = {} for better intellisense.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

}

// Put claims in the request object for downstream use.
req.authInfo = payload;
Copy link
Collaborator

Choose a reason for hiding this comment

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

you could also have this middleware add the userid to the request, so you have a single location that gets the user id

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! I added this change.

@davidchesnut davidchesnut merged commit 66c340d into main Apr 10, 2025
1 check passed
@davidchesnut davidchesnut deleted the davech-naa-id branch April 10, 2025 22:01
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.

5 participants