This question got me most of the way there. I successfully generate a token, but get a 403.
Function app (FA) serves an API that is consumed by 1 WebApps ApplicationId.
All identites are authorized.
I would like to test without the webapp, preferrably with postman.
My guess is I am not generating the client credential correctly: ClientId: Is this the FA that is serving? Client Secret: Has to be the FA that is serving the API, Object Id: Which Object FA or WA (although I got a token without including) Scope: {FA clientid}/.default Auth endpoint, Token endpoint.
Is ClientCredentials the correct GrantType. I cannot use Password because tenant requires 2-Factor Open to Implicit or AuthCode, but I could not figure out the right parameters for them.
Created an Azure Function app and added identity provider as Microsoft:
Now I edited the Identity provider and allowed requests from specific client application:
In the application and API will be exposed:
In the Microsoft Entra ID application, I granted API permissions like below:
And generated access token for client application:
scope : ClientID/.default
I got the same error:
The 403 error usually occurs if the access token does not have required permissions to perform the action.
To resolve the error, make sure to pass scope as api://ClientAppID/.default
not ClientAppID/.default
api://ClientAppID
and save like below:Now regenerate the access token by passing scope as api://ClientAppID/.default
:
GET https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
client_id : ClientID
client_secret : Secret
scope : api://xxx/.default
grant_type : client_credentials
I am able to successfully access the function API:
GET https://rukfapp.azurewebsites.net/api/HttpTrigger2
If you are making use of two different applications, one for identity provider and one more as client application then make sure to either grant API permissions to client application from the identity provider app OR configure client app as allowed audience in identity provider.