Prepare external tenant for calling an API in a Node.js web application
Applies to: Workforce tenants External tenants (learn more)
In this article, you prepare your external tenant for authorization. This article is the first part of a four-part guide.
Prerequisite
Complete the steps in Tutorial: Prepare your external tenant to sign in users in a Node.js web app. After you complete this tutorial, you register an app in your customer's tenant, and you've a web app that signs in users. We refer to this web application as the client application. You extend this application to call a protected web API.
Complete the steps in Tutorial: Secure an ASP.NET web API registered in an external tenant. After you complete this tutorial, you register a web API in your customer's tenant, which exposes API permissions and publishes application roles. You also have a secured web API. You call this web API from the client web application.
Configure idtyp token claim [optional]
You can idtyp optional claim to help the web API to determine if a token is an app token or an app + user token. Although you can use a combination of scp and roles claims for the same purpose, using 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 steps in Configure optional claims article to add idtyp claim to the access token:
- For the Token type select Access.
- From the optional claims list, select idtyp.
Grant API permissions to the web app
From the prerequisites, you registered a client app in your customer's tenant. You also registered a web API app in your customers. Now, you need to grant API permissions to your client app:
From the App registrations page, select the application that you created (such as ciam-client-app) to open its Overview page.
Under Manage, select API permissions.
Under Configured permissions, select Add a permission.
Select the APIs my organization uses tab.
In the list of APIs, select the API such as ciam-ToDoList-api.
Select Delegated permissions option.
From the permissions list, select ToDoList.Read, ToDoList.ReadWrite (use the search box if necessary).
Select the Add permissions button.
At this point, you've assigned the permissions correctly. However, since the tenant is a customer's tenant, the consumer users themselves can't consent to these permissions. To address this, 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.
From the Configured permissions list, select the ToDoList.Read and ToDoList.ReadWrite permissions, one at a time, and then copy the permission's full URI for later use. The full permission URI looks something similar to
api://{clientId}/{ToDoList.Read}
orapi://{clientId}/{ToDoList.ReadWrite}
.
Next step
Next, learn how to prepare your web application and API.