0

I have an AAD Application - ABC, that needs to access other application XYZ via an exposed api which is - "api://XYZ/general". I`m trying to use MSAL library and using ConfidentialClientApplication mechanism,but it is constantly giving me an error stating -

AADSTS500011: The resource principal named api://XYZ/general was not found in the tenant named ***. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.

Can someone please assist me on how to resolve this error? I have been blocked on this for quite some time now.

Trying to get access token to use Easy Start APIs. Code-

authority = app.config["AUTHORITY"] + '/' + app.config["TENANT"]

aadApp = msal.PublicClientApplication(app.config["CLIENT_ID"], authority=authority)

result = None
accounts = aadApp.get_accounts()
if accounts:
    # If a user account exists, use it to acquire a token silently
    result = aadApp.acquire_token_silent(scopes=app.config["OB_SCOPE"], account=accounts[0])

if not result:
    # No user account or token acquisition failed, perform interactive authentication
    result = aadApp.acquire_token_interactive(scopes=app.config["OB_SCOPE"])

access_token = result['access_token']

Error- enter image description here

1 Answers1

0

I have one application named WebAPI where I exposed an API with same scope as you:

enter image description here

Now, I registered one Azure AD application named ClientApp18 and added above permissions in API permissions tab:

enter image description here

To generate access token, I directly used interactive flow by modifying your python code:

import msal

tenant_id = "fb134080-e4d2-45f4-9562-fxxxxxxxxx0"
client_id = "3b48a780-de28-4576-b1c5-exxxxxxxx2"

scopes = ["api://5bc992e5-b3f8-4cfc-8197-aexxxxxxa/general"]

authority = f"https://login.microsoftonline.com/{tenant_id}/"

aadApp = msal.PublicClientApplication(client_id, authority=authority)

result = aadApp.acquire_token_interactive(scopes=scopes)

if "access_token" in result:
    access_token = result['access_token']
    print("Access token:", access_token)
else:
    print("Interactive authentication failed. Please check your Azure AD configuration.")

When I ran the above code, a new window opened to pick an account to sign in like this:

enter image description here

Make sure to select right user account from same tenant where the applications exist and you will get below screen once Authentication is successful:

enter image description here

After authenticating, I got the access token successfully in the output console:

enter image description here

To confirm that, I decoded the above token in jwt.ms and got aud & scp claims with correct values:

enter image description here

In your case, check whether you are already logged in with user from different tenant other than the tenant where applications exist or passed wrong tenantID in code.

When I ran the code by selecting user from different tenant or including wrong tenantID, I got similar error as you:

enter image description here

To resolve the error, try to use interactive flow directly as I mentioned by signing in with right user account from same tenant where the applications exist and check whether you are using right tenantID or not.

Sridevi
  • 10,599
  • 1
  • 4
  • 17
  • I tried the similar steps which you mentioned, I'm still facing the same issue. I'm using the same tenant ID and my user is also in the same tenant. Still getting the same issue. Just curious, could this error if `WebAPI` has not granted admin consent to `ClientApp18` in your case? – Sunamya Gupta Jul 18 '23 at 16:12
  • In my case, I signed in with user of different tenant by passing wrong `tenantID`. Have you granted **admin consent** to added API permissions? – Sridevi Jul 18 '23 at 16:17
  • Did you run same code as mine and still got same error? Could you include exposed API and API permissions screenshot by editing your question? – Sridevi Jul 18 '23 at 16:19
  • Sorry, I made a mistake above. My applications are in two different tenants. Application1 which has exposed an API is in tenant1 and Application2(multi-tenant AAD app) which wants to use that exposed API is in tenant2. But we already have an enterprise application of Application1 in tenant2 – Sunamya Gupta Jul 18 '23 at 17:22