Microsoft Entra ID
Let people who sign in with Microsoft call your API. MSAL gets a token for your API, and your API verifies it against Microsoft's public keys.
When your app signs people in with Microsoft through MSAL, Entra ID signs an access token for your API. Your API verifies it with @kizunajs/jwt, and app roles you assign in Entra arrive as the caller's roles.
Entra ID was called Azure Active Directory until 2023, so this page covers both.
Register your API
In the Entra admin center, under App registrations, register an app for your API:
- Under Expose an API, set the Application ID URI to
api://<api-client-id>and add a scope, likeaccess_as_user. - In the Manifest, set
requestedAccessTokenVersionto2. Without it, Entra signs v1.0 tokens, which carry another issuer and audience. - Under App roles, add the roles your API checks, like
memberandadmin, and assign them to people under Enterprise applications.
Declare the identity
<tenant-id> and <api-client-id> are on your API's Overview page:
oid is the person's id in your tenant, the same in every app. roles holds the app roles they were assigned, and a role your API does not declare is left out.
Get a token for your API
The app asks MSAL for your API's scope, and sends the token before every request:
MSAL keeps the token and refreshes it, so acquireTokenSilent only calls Microsoft when it has to.
Ask for your API's scope, not Microsoft Graph
The token MSAL returns for User.Read is for Microsoft Graph. Its audience is Graph, and your API cannot verify it, so it answers 401. Request
api://<api-client-id>/... for calls to your API.
One tenant
The issuer names one tenant, so only people from that organization get in. An API open to every Microsoft organization has to check each tenant's issuer itself, which this page does not cover.