Skip to main content

How to Pre-Authorize a Client Application for Your API in Microsoft Entra ID

· 12 min read
Jagdish Kumawat
Founder @ Dewiride

When an app asks for a scope of your API, someone has to agree to it first: the person signing in, or an administrator for everyone. For apps you build or trust yourself, that question is noise. Your API can pre-authorize them, and their users are never asked. This guide pre-authorizes two apps, the Azure CLI and a single-page app, in the Microsoft Entra admin center and with the Azure CLI.

What Pre-Authorizing Does​

The Expose an API page says it in one sentence: Authorizing a client application indicates that this API trusts the application and users should not be asked to consent when the client calls this API. The trust is narrow. Microsoft Graph's documentation puts it this way: Users aren't required to consent to any preauthorized application (for the permissions specified). However, any other permissions not listed in preAuthorizedApplications … require user consent.

So each authorization names one app and the scopes it may use without asking. Microsoft's guide adds a warning worth taking literally: pre-authorize only those client applications you trust, since your users won't have the opportunity to decline consent.

Two apps commonly earn that trust:

AppWhy pre-authorize it
The Azure CLIDevelopers get tokens for the API from the command line to test it. Its client ID is 04b07795-8ddb-461a-bbee-02f9e1bf7b46, the ID Microsoft's documentation lists for the Microsoft Azure CLI
Your own front endYou built both the app and the API, so a consent screen between them asks people a question only you can answer

The examples on this page work on an API registration called Dewiride Service Desk API, with a scope named access_as_user (How to Expose an API Scope in Microsoft Entra ID).

Prerequisites​

  • Permission to change the API's registration: you're listed under its Owners, or you have a role such as Cloud Application Administrator.
  • The client ID of each app you want to authorize. For your own app, it's the Application (client) ID on its registration's Overview page.
  • For the Azure CLI route: the Azure CLI signed in to the API's tenant (az login).

What Happens Without It​

A token for your own API, asked for with the Azure CLI before the API trusts it, shows why this step exists:

Output
ERROR: AADSTS9002313: Invalid request. Request is malformed or invalid. Trace ID: 00000000-0000-0000-0000-000000000000 Correlation ID: 00000000-0000-0000-0000-000000000000 Timestamp: 2026-11-19 10:44:34Z
Run the command below to authenticate interactively; additional arguments may be added as needed:
az logout
az login --tenant "11111111-1111-1111-1111-111111111111" --scope "api://22222222-2222-2222-2222-222222222222/access_as_user"

The message hides the cause. With --debug, the real one shows up: AADSTS65001: The user or administrator has not consented to use the application with ID '04b07795-8ddb-461a-bbee-02f9e1bf7b46' named 'Microsoft Azure CLI'. Nobody had agreed that the Azure CLI may use the scope. The full investigation is in Fixed: AADSTS9002313 When the Azure CLI Gets a Token for Your Own API.

Step 1: Add the Azure CLI​

In the Microsoft Entra admin center, open your API's registration under Entra ID > App registrations, and select Expose an API under Manage. Under Authorized client applications, select Add a client application, and fill in the panel:

FieldValue
Client ID04b07795-8ddb-461a-bbee-02f9e1bf7b46
Authorized scopesSelect api://<client ID>/access_as_user

The Add a client application panel with the Client ID 04b07795-8ddb-461a-bbee-02f9e1bf7b46, the scope api://22222222-2222-2222-2222-222222222222/access_as_user selected under Authorized scopes, and the Add application button highlighted

Select Add application. The page lists the Azure CLI with the number of scopes it may use:

The Expose an API page with the Application ID URI api://22222222-2222-2222-2222-222222222222, the access_as_user scope that Admins and users can consent to and that is Enabled, and under Authorized client applications the Client Id 04b07795-8ddb-461a-bbee-02f9e1bf7b46 with 1 scope

The same token command now works. The Azure CLI is a tool for developers: this authorization lets anyone in your organization who uses it get a token for the API, which is what you want while you build and test (How to Get an Access Token for Your Own API with the Azure CLI).

Step 2: Add Your Own App​

Your own front end is authorized the same way, with its client ID. Here it's a single-page app registered as Dewiride Service Desk Chat, shown as 33333333-…:

The Add a client application panel with the Client ID 33333333-3333-3333-3333-333333333333, the scope api://22222222-2222-2222-2222-222222222222/access_as_user selected and the Add application button highlighted

After Add application, both apps are listed:

The Expose an API page of the Dewiride Service Desk API with the Application ID URI, the access_as_user scope, and two authorized client applications: the Azure CLI 04b07795-8ddb-461a-bbee-02f9e1bf7b46 and the chat app 33333333-3333-3333-3333-333333333333, each with 1 scope

People who sign in to the chat app are no longer asked to let it use the API. The authorization covers access_as_user only. When the same app asked for nothing but to sign someone in, Microsoft still showed a consent screen, for View your basic profile and Maintain access to data you have given it access to: those permissions aren't on the list. The app's own registration should also list the permission it asks for (How to Add an API Permission to an App Registration in Microsoft Entra ID).

Do It with the Azure CLI​

az ad app has no option for authorized client applications, so this goes to Microsoft Graph, the API behind the admin center, with az rest. The examples work on an API registration called My Web API and a single-page app called My Single-Page App. First, collect the three IDs the update needs — the API's client ID, its scope's ID and the app's client ID:

Terminal
API_APP_ID=$(az ad app list --display-name "My Web API" --query "[0].appId" --output tsv)
SCOPE_ID=$(az ad app show --id $API_APP_ID --query "api.oauth2PermissionScopes[?value=='access_as_user'].id" --output tsv)
SPA_APP_ID=$(az ad app list --display-name "My Single-Page App" --query "[0].appId" --output tsv)

The second line finds the ID of the scope whose name is access_as_user: authorizations refer to scopes by ID, not by name.

Now write the list of trusted apps into a file named preauth.json and send it:

Terminal
cat > preauth.json <<EOF
{
"api": {
"preAuthorizedApplications": [
{
"appId": "04b07795-8ddb-461a-bbee-02f9e1bf7b46",
"delegatedPermissionIds": ["$SCOPE_ID"]
},
{
"appId": "$SPA_APP_ID",
"delegatedPermissionIds": ["$SCOPE_ID"]
}
]
}
}
EOF
az rest --method PATCH --uri "https://graph.microsoft.com/v1.0/applications(appId='$API_APP_ID')" --body @preauth.json

az rest prints nothing when the update works. Each entry is one row of Authorized client applications:

FieldIn the admin center
appIdClient ID
delegatedPermissionIdsAuthorized scopes, as the scopes' IDs

Write every app the API should trust into the file, including those already authorized, so the list you send is the list you want. Sending only preAuthorizedApplications inside api left the API's scopes as they were. Check the result:

Terminal
az ad app show --id $API_APP_ID --query "api.preAuthorizedApplications"
Output
[
{
"appId": "55555555-5555-5555-5555-555555555555",
"delegatedPermissionIds": [
"66666666-6666-6666-6666-666666666666"
]
},
{
"appId": "04b07795-8ddb-461a-bbee-02f9e1bf7b46",
"delegatedPermissionIds": [
"66666666-6666-6666-6666-666666666666"
]
}
]

Both apps are there, each with the scope's ID. A token for the API now comes back without an error:

Terminal
az account get-access-token --scope "api://$API_APP_ID/access_as_user" --query "{expiresOn:expiresOn, tokenType:tokenType}"
Output
{
"expiresOn": "2026-11-19 20:04:33.000000",
"tokenType": "Bearer"
}

Common Mistakes​

MistakeWhat happensDo this instead
Pre-authorizing an app you don't controlIts users can call your API through it without ever being askedAuthorize only the apps you build or fully trust
Entering the app's Object ID instead of its client IDThe API trusts an ID the app never presents: apps ask for tokens with their client IDCopy Application (client) ID from the app's Overview
Authorizing one scope and asking for anotherThe other scope still needs consent: the Azure CLI fails with AADSTS9002313Authorize every scope the app asks for, or ask only for authorized ones
Leaving existing apps out of preauth.jsonThe list you send may not be the list you wantWrite the full list every time

Troubleshooting​

SymptomLikely causeFix
AADSTS9002313 from az account get-access-tokenRun it with --debug: AADSTS65001 means the Azure CLI isn't authorized for that scopeAuthorize the Azure CLI for the scope, as in Step 1
AADSTS9002313 although the Azure CLI is authorizedThe scope in the command isn't one it's authorized for. A misspelled scope name ended the same way, with AADSTS65001 behind itCheck the scope name in the command against Expose an API
A consent screen still appears in your appThe app asks for permissions the API didn't pre-authorize, such as those for signing inExpected for those permissions: the person consents once
Add a client application is dimmedThe API has no scope yetAdd a scope first

FAQ​

No. Admin consent is an administrator agreeing, for everyone in the organization, that an app may use a permission. Pre-authorizing is the API itself declaring that it trusts an app for some of its scopes, and it's set on the API's registration by whoever owns it.

Should I pre-authorize the Azure CLI in production?​

It's a developer tool: anyone in your organization who uses it could get a token for the API. That's useful while you build and test. For an API whose users should only reach it through your own apps, remove the Azure CLI from the list before it goes live.

Does pre-authorizing grant app-only access?​

No. It's for delegated scopes, where an app acts for a signed-in person, as its field name, delegatedPermissionIds, says. An app that calls the API on its own, with no one signed in, gets an app role instead.

Conclusion​

Pre-authorizing lets your API trust the apps you choose, for the scopes you choose, without asking their users to consent. Add each app under Authorized client applications on Expose an API with its client ID and its scopes, or send the list to Microsoft Graph with az rest. Authorize the Azure CLI, 04b07795-8ddb-461a-bbee-02f9e1bf7b46, to test your API from the command line, and your own front end so its users go straight in.

Additional Resources​