MSAL Python Service account Token genration error

Azad Patel 1 Reputation point
2022-03-08T19:08:48.557+00:00

Hi Team,

Currently we are using Application Registration details to generate the application token and use the same application token to access Elastic API.
Ref : https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app

Now we are working on Generating token using Service account. Service account will be added to the AzureAD group and AzureAD group will be added to the Application Registration.
We have configured the Application Registration with service account and AzureAD groups. We are getting error while generating the token :

Description: AADSTS90009: Application 'b81f5f82-aa4e-7e7cf93acddd'(b81f5f82-aa4e-7e7cf93acddd) is requesting a token for itself. This scenario is supported only if resource is specified using the GUID based App Identifier.
Trace ID: 4f9785cd-1f4d-4a16-8131-a5b2f1f6a600
Correlation ID: d6ea6328-bc71-4fa1-8c8a-473ae55ce0c1

To generate the token using Service account we are using MSAL library with python, we are following below link for reference
Ref : https://learn.microsoft.com/en-us/python/api/overview/azure/msal-python-overview?view=azure-python
Ref : https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki/Username-Password-Authentication

Could you please help me resolving this error ?

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,431 Reputation points Microsoft Employee Moderator
    2022-03-09T10:43:39.9+00:00

    Hi @Azad Patel ,

    Thanks for reaching out.

    From your query I understand you are getting error when requesting the token for Web API.

    This error is due to scope has not been set correctly in the request while acquiring the token.

    Can you share the request and endpoint you are using to get the access token?

    If you are using v2 endpoint then it is mandatory to send the scope parameter with app ID URI (api://<application-client-id>) specify the permission, you are requesting for Web API.

    Reference : Expose a web API

    Thanks,
    Shweta

    ------------------------------------------------

    Please remember to "Accept Answer" if answer helped you.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.