Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
It turns out that the authentication needs a username and password, it can't accept client credential flow. I got it sorted. thanks
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi there
I created the following in Azure.
A Web App which is an API to be used by a MAUI application
An Enterprise Application for the Web App
A service principal for the web app.
When I use the MAUI application, the login is fine and the authentication works perfectly. The problem I am facing is that I need to connect to the api from an Excel workbook and for that I need to acquire a token and pass that through. In postman I am using https://login.microsoftonline.com/{tenantid}/oauth2/v2.0/token to get a token. I pass in the client id, secret and scope and get back a token. I have used two different scopes. {clientId}/.default and https://management.azure.com/.default
For both I get back an access token, but neither works when I try and access the api. Could you please tell me what I am doing wrong. The api simply has [Authorize] decorated over the api methods, so it should just be making sure that it has a valid token. But I can't get it to return a simple get request.
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
Locked Question. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer recommended by moderator
It turns out that the authentication needs a username and password, it can't accept client credential flow. I got it sorted. thanks
Hello @Jai Holloway
Thank you for confirming that your issue is resolved. Yes in some scenarios, it may not take client secret rather requires username and password. Please feel free to reach out to us in case of any further queries.
AI answer
The API isn’t accepting the tokens because the access token you’re acquiring isn’t issued for your API. It’s being issued for other resources (management.azure.com or the client app itself), so the aud (audience) claim doesn’t match what the API expects.
For an ASP.NET / ASP.NET Core API protected with [Authorize] and Microsoft Entra ID, the token must:
Use the following checks and steps:
api://{api-app-client-id} or a custom URI).api://{api-app-client-id}/Forecast.Read.scope must be either:
api://{application_client_id}/SomeScope (a specific delegated scope), orapi://{application_client_id}/.default (for application permissions / client credentials against that API),https://management.azure.com/.default unless calling Azure Resource Manager.{clientId}/.default where {clientId} is the client app; it must be the API’s Application ID URI.SCOPE: api://{application_client_id}/Forecast.Read{application_client_id} is the web API registration, not the client./.default, you can hit issues like described in the AADSTS50000 scenario; the fix is to expose delegated permissions when using delegated flows.POST https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/tokengrant_type=client_credentialsclient_id={client-id-of-calling-app}client_secret={secret-of-calling-app}scope={Application-ID-URI-of-API}/.default (for example api://contoso.azurewebsites.net/aaaabbbb-0000-cccc-1111-dddd2222eeee/.default)aud)
aud equals the API’s client ID (or Application ID URI, depending on configuration).iss matches the tenant.aud is https://management.azure.com/ or something other than your API, the API will reject it.AcquireTokenSilent / interactive login with the correct scopes for the API, as described in the “web app that calls web APIs” scenario./.default
/.default and the resource app exposes only application permissions, you must:
Once the token is requested for the correct Application ID URI and scopes, and the API is configured to accept that type of token (delegated or application), the [Authorize] attribute will accept the token and the GET request should succeed.
References: