MSAL AcquireTokenInteractive code hangs / infinte loop when web application hosts on IIS

SyncTestUser1 1 Reputation point
2020-09-10T18:17:32.707+00:00

I am using this chunk of code to get the access token. code is working fine on IIS Express but when I host web app in to IIS then code hangs and went in to infinite loop.

                authResult = await app.AcquireTokenInteractive(scopes).WithUseEmbeddedWebView(true)
                .ExecuteAsync();

I also opened the firewall ports on windows.

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,454 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Saurabh Sharma 23,671 Reputation points Microsoft Employee
    2020-09-14T23:17:15.777+00:00

    @SyncTestUser1 Thanks for sharing your code. Your web apps should use IConfidentialClientApplication and not PublicClientApplicationOptions. Publicclientapplication is not intended to be used like that. Also, as your IIS runs under a differential credential set but cannot interact with the current login user session and being a remote process IIS is not capable of launching a browser as compared to IIS express your calls are stuck. Please let me know how it goes after the modification.

    Also, it may be good idea to use aync/await pattern instead of wait() in your code.


  2. TEJENDRA PRASAD PATEL 111 Reputation points
    2021-04-01T11:09:59.673+00:00

    Hi,

    I am trying to acquire Token using certificate to connect Graph API. Its works in console application and local IIS express.

    However, when hosted same in IIS it get stuck and timed out.

    var msalClient = ConfidentialClientApplicationBuilder
                .Create(config.ClientID)
                .WithCertificate(GetCertificateByThumbprint(config.ApplicationThumbprint))
                .WithAuthority(AadAuthorityAudience.AzureAdMyOrg, true)
                .WithTenantId(config.TenantID)
                .Build();
    
             result = await msalClient.AcquireTokenForClient(scopes).ExecuteAsync(); // ****Gets Stuck** - IT DOES NOT EVEN GO TO NEXT STEP**
    
            requestMessage.Headers.Authorization =
                new AuthenticationHeaderValue("bearer", await GetAccessTokenAsync());
    
            var users = await graphClient.Users.Request().Filter($"mail eq '{emailAddress}'").GetAsync();
    

    I have createD ASP.NET MVC for poc and will convert into Web API.

    I do not want to use user login token or such... There is no login page and we want to interact MS Graph API using application specific Client ID.

    Please some one help on this.

    thank you!

    0 comments No comments