I created a new Azure App Registration (App1) and exposed as an API. The MS Graph API permission which it has is:
Application.ReadWrite.OwnedBy - Application (Admin consent granted)
GroupMember.Read.All - Delegated (Admin consent granted)
User.Read - Delegated
User.Read.All - Delegated (Admin consent granted)
The version for the App Registration is 2 (I can see this: "accessTokenAcceptedVersion": 2 under the Manifest).
I have another App Registration (App2) and I haven't added the above App Registration's API permission to the second App Registration. The only API permission the second App has is:
User.Read - Delegated
I use curl command to get the token for the first App from second app like below:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" \
-d 'client_id=client-id-of-app2' \
-d 'client_secret=client-secret-of-app2' \
-d 'grant_type=client_credentials' \
-d 'scope=api://client-id-of-app1/.default' \
'https://login.microsoftonline.com/my-tenant/oauth2/v2.0/token'
After I use the above command, I can successfully get the token. But my question is, how come the second app able to get a token from first app even without adding the API permission of first app in the second app?
I have another Azure App (App3) and has exposed as an API. When I use curl from App2 to App3 it gives below error:
'https://login.microsoftonline.com/123/oauth2/v2.0/token'
{"error":"invalid_grant","error_description":"AADSTS501051: Application 'Client ID of App2'(App2) is not assigned to a role for the application 'api://client-id-of-app3'(App3). "error_uri":"https://login.microsoftonline.com/error?code=123"}%
Why App3 gives above error and App1 generates a token when App2 uses curl command?