Forum Discussion

stevenamani's avatar
stevenamani
Advocate II
8 years ago
Solved

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;

        }

  • stevenamani's avatar
    stevenamani
    8 years ago

    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.

2 Replies

  • v-micsh-msft's avatar
    v-micsh-msft
    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

    • stevenamani's avatar
      stevenamani
      Advocate II

      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.