Tutorial: Prepare your customer tenant to authorize a Node.js daemon application
In this tutorial, you learn how to acquire an access token, then call a web API in a Node.js daemon application. You enable the client daemon app to acquire an access token using its own identity. To do so, you first register your application in your Microsoft Entra ID for customers tenant.
In this tutorial, you'll:
- Register a web API and configure app permissions in the Microsoft Entra admin center.
- Register a client daemon application, the grant it app permissions in the Microsoft Entra admin center.
- Create a client secret for your daemon application in the Microsoft Entra admin center.
If you've already registered a client daemon application and a web API in the Microsoft Entra admin center, you can skip the steps in this tutorial, then proceed to Acquire access token for calling an API.
Prerequisites
- A Microsoft Entra ID for customers tenant. If you don't already have one, sign up for a free trial.
Register a web API application
Sign in to the Microsoft Entra admin center as at least an Application Developer.
If you have access to multiple tenants, use the Settings icon
in the top menu to switch to your customer tenant from the Directories + subscriptions menu.
Browse to Identity > Applications > App registrations.
Select + New registration.
In the Register an application page that appears, enter your application's registration information:
In the Name section, enter a meaningful application name that will be displayed to users of the app, for example ciam-ToDoList-api.
Under Supported account types, select Accounts in this organizational directory only.
Select Register to create the application.
The application's Overview pane is displayed when registration is complete. Record the Directory (tenant) ID and the Application (client) ID to be used in your application source code.
Configure app roles
An API needs to publish a minimum of one app role for applications, also called Application Permission, for the client apps to obtain an access token as themselves. Application permissions are the type of permissions that APIs should publish when they want to enable client applications to successfully authenticate as themselves and not need to sign-in users. To publish an application permission, follow these steps:
From the App registrations page, select the application that you created (such as ciam-ToDoList-api) to open its Overview page.
Under Manage, select App roles.
Select Create app role, then enter the following values, then select Apply to save your changes:
Property Value Display name ToDoList.Read.All Allowed member types Applications Value ToDoList.Read.All Description Allow the app to read every user's ToDo list using the 'TodoListApi' Select Create app role again, then enter the following values for the second app role, then select Apply to save your changes:
Property Value Display name ToDoList.ReadWrite.All Allowed member types Applications Value ToDoList.ReadWrite.All Description Allow the app to read and write every user's ToDo list using the 'ToDoListApi'
Configure idtyp token claim
Tokens returned by Microsoft identity are kept smaller to ensure optimal performance by clients that request them. As a result, several claims are no longer present in the token by default and must be asked for specifically on a per-application basis. For this app, you include idtyp optional claim to help the web API to determine if a token is an app token or an app+user token. Although a combination of scp and roles claims can used for the same purpose, the use of the idtyp claim is the easiest way to tell an app token and an app+user token apart. For example, the value of this claim is app when the token is an app-only token.
Use the following steps to configure idtyp optional claim:
Under Manage, select Token configuration.
Select Add optional claim.
Under Token type, choose Access.
Select the optional claim idtyp.
Select Add to save your changes.
Register the daemon app
To enable your application to sign in users with Microsoft Entra, Microsoft Entra ID for customers must be made aware of the application you create. The app registration establishes a trust relationship between the app and Microsoft Entra. When you register an application, External ID generates a unique identifier known as an Application (client) ID, a value used to identify your app when creating authentication requests.
The following steps show you how to register your app in the Microsoft Entra admin center:
Sign in to the Microsoft Entra admin center as at least an Application Developer.
If you have access to multiple tenants, use the Settings icon
in the top menu to switch to your customer tenant from the Directories + subscriptions menu.
Browse to Identity >Applications > App registrations.
Select + New registration.
In the Register an application page that appears;
- Enter a meaningful application Name that is displayed to users of the app, for example ciam-client-app.
- Under Supported account types, select Accounts in this organizational directory only.
Select Register.
The application's Overview pane displays upon successful registration. Record the Application (client) ID to be used in your application source code.
Create a client secret
Create a client secret for the registered application. The application uses the client secret to prove its identity when it requests for tokens.
- From the App registrations page, select the application that you created (such as ciam-client-app) to open its Overview page.
- Under Manage, select Certificates & secrets.
- Select New client secret.
- In the Description box, enter a description for the client secret (for example, ciam app client secret).
- Under Expires, select a duration for which the secret is valid (per your organizations security rules), and then select Add.
- Record the secret's Value. You'll use this value for configuration in a later step.
Note
The secret value won't be displayed again, and is not retrievable by any means, after you navigate away from the Certificates and secrets page, so make sure you record it.
For enhanced security, consider using certificates instead of client secrets.
Grant API permissions to the daemon app
From the App registrations page, select the application that you created, such as ciam-client-app.
Under Manage, select API permissions.
Under Configured permissions, select Add a permission.
Select the My APIs tab.
In the list of APIs, select the API such as ciam-ToDoList-api.
Select Application permissions option. We select this option as the app signs in as itself, not users.
From the permissions list, select TodoList.Read.All, ToDoList.ReadWrite.All (use the search box if necessary).
Select the Add permissions button.
At this point, you've assigned the permissions correctly. However, since the daemon app doesn't allow users to interact with it, the users themselves can't consent to these permissions. To address this problem, you as the admin must consent to these permissions on behalf of all the users in the tenant:
- Select Grant admin consent for <your tenant name>, then select Yes.
- Select Refresh, then verify that Granted for <your tenant name> appears under Status for both permissions.
Collect your app registration details
In the next step, you prepare your daemon app application. Make sure you've the following details:
- The Application (client) ID of the client daemon app that you registered.
- The Directory (tenant) subdomain where you registered your daemon app. If you don't have your tenant name, learn how to read your tenant details.
- The application secret value for the daemon app you created.
- The Application (client) ID of the web API app you registered.
Next steps
In the next tutorial, you prepare your daemon Node.js application.
Feedback
Submit and view feedback for