Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
stevenamani
Advocate II
Advocate II

Code Hanging on Acquire Token

I am attempting to acquire a token from AzureAD in a native app and while this works fine on a number of computers, I have one where the application just hangs. Here is the code:

 

public async Task<string> GetTokenAAD()

        {

            //example https://docs.microsoft.com/en-us/power-bi/developer/get-azuread-access-token

 

           var credential = new UserPasswordCredential(this.userName, this.password);

 

            var authenticationContext = new AuthenticationContext(Properties.Settings.Default.AADAUTH_URL);

 

 

            authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, this.clientID, credential); //code hangs here

 

            if (authenticationResult != null)

            {

                return authenticationResult.AccessToken;

            }

 

            return string.Empty;

        }

1 ACCEPTED SOLUTION

Turns out the issue was unrelated to PowerBI or Azure AD. The function was being called from a non-async function and I resolved it by adding ConfigureAwait(True) to the AcquiteTokenAsync call.

View solution in original post

2 REPLIES 2
v-micsh-msft
Microsoft Employee
Microsoft Employee

Could you please explain a bit for " application just hangs" ?

 

If it hangs in Windows, there should be application log generated for this event, please take a check under Event Viewer and see if any specific error message logged.

Further, for Windows Application hang, please check:

Extracting Information from Crash and Hang Dumps

 

Regards,

Michael

Turns out the issue was unrelated to PowerBI or Azure AD. The function was being called from a non-async function and I resolved it by adding ConfigureAwait(True) to the AcquiteTokenAsync call.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Kudoed Authors