Issue with the flow microsoft-authentication-library-for-dotnet and Username Password

Vasileios Klouvatos 1 Reputation point

We have one application with an Web API .net core project. We provide an http endpoint for login. We are using the in order authenticate the user and also provide a token based on the application id that is registered to the Azure. The application already contains granted scopes to access to office 365 resources. The application also is configured to Allow public client flows => True.

We are getting a token when we call the function AcquireTokenByUsernamePassword(....) but the token is not valid to make the request to the office 365 http resource.
When i am trying to use the token to send an HTTP GET request to the
I am getting the following error :
Code : InvalidAuthenticationToken
Message : Invalid x5t claim

Could you please help me to debug why i am getting this error?

Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
210 questions
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,032 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,124 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,021 Reputation points

    Hi @Vasileios Klouvatos ,

    Per my test, this way to get the access token works fine on my end. You could share the code you use so I could help you more.
    Below is my demo code:

        private static async Task<string> GetATokenForGraph()  
            string applicationId = "xxxx";  
            string tenantId = "";  
            IPublicClientApplication confApp = PublicClientApplicationBuilder.Create(applicationId)  
            var userName = "";  
            var password = "xxx";  
            var securePassword = new SecureString();  
            foreach (char c in password)  
            var scopes = new string[] { "" };  
            var authenticationResult = await confApp.AcquireTokenByUsernamePassword(scopes, userName, securePassword).ExecuteAsync();  
            return authenticationResult.AccessToken;  

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.