Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] AcquireTokenInteractive with WAM broker immediately returns UserCanceled when running as Administrator #4894

Closed
bojordan opened this issue Aug 14, 2024 · 4 comments

Comments

@bojordan
Copy link

bojordan commented Aug 14, 2024

Library version used

4.63.0

.NET version

net8.0

Scenario

PublicClient - desktop app

Is this a new or an existing app?

The app is in production, and I have upgraded to a new version of MSAL

Issue description and reproduction steps

When using MSAL's PublicClientApplicationBuilder with WAM via .WithBroker() and running as Administrator, AcquireTokenInteractive() immediately fails with an error saying the user closed the interactive session. The WAM account selection dialog often pops up, but often the console running the application will lose focus and is no longer responsive to the user's mouse or keyboard input.

When a token is already present for the user, AcquireTokenSilent() is successful, even when running as Administrator.

Relevant code snippets

// Happy to provide a sample project that reproduces the issue with internal Microsoft identities

IPublicClientApplication publicApp = PublicClientApplicationBuilder
    .Create(settings.ApplicationId)
    .WithAuthority(settings.AuthorityUri)
    .WithParentActivityOrWindow(GetConsoleOrTerminalWindow)
    .WithBroker(new BrokerOptions(BrokerOptions.OperatingSystems.Windows)
    {
        ListOperatingSystemAccounts = true,
    })
    .WithDefaultRedirectUri()
    .WithLogging(
        (level, message, containsPii) =>
        {
            // logging
        },
        Microsoft.Identity.Client.LogLevel.Verbose,
        enablePiiLogging: true)
    .Build();

var accounts = await publicApp.GetAccountsAsync();

AuthenticationResult result = null;
foreach (var acct in accounts)
{
    try
    {
        result = await publicApp.AcquireTokenSilent(scopes, acct).ExecuteAsync();
    }
    catch (MsalUiRequiredException)
    {
        // don't interact here
    }

    if (result != null) break;
}

try
{
    if (result == null)
    {
        result = await publicApp.AcquireTokenInteractive(scopes).ExecuteAsync();
    }
}
catch (MsalClientException ex)
{
    // logging
}

Expected behavior

When a valid account+token is not availabe in the accounts list, I expect AcquireTokenSilent() to fail for all enumerated accounts. When running as Administrator, I expect AcquireTokenInteractive() to engage with the WAM broker to pop up an account selection dialog while the code blocks on the user interact. Instead, the dialog is sometimes shown, but the interop with WAM immediately returns:

[RuntimeBroker] Could not sign in interactively. Status: UserCanceled Context: User cancelled the Accounts Control Operation. Tag: 0x1f7d734a

Identity provider

Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)

Regression

No response

Solution and workarounds

Current work-around is to not use WAM broker when running as Administrator.

@bojordan bojordan added needs attention Delete label after triage untriaged Do not delete. Needed for Automation labels Aug 14, 2024
@ashok672
Copy link
Contributor

ashok672 commented Aug 18, 2024

@bojordan - This issue has been fixed already. Make sure Microsoft.Identity.Client.NativeInterop version is 0.16.2

@suprak
Copy link

suprak commented Aug 18, 2024

@ashok672 Microsoft.Identity.Client.Broker should be updated with new dependency?
That is how we are pulling in Microsoft.Identity.Client.NativeInterop.
Currently that is depending on 0.16.1

@gustavoaca1997
Copy link

We have the same issue. If we manually import Microsoft.Identity.Client.NativeInterop 0.16.2, it starts working again.

@bojordan
Copy link
Author

Thanks @ashok672 and @gustavoaca1997 : Verified this fixes the issue.

@bgavrilMS bgavrilMS added bug P2 and removed untriaged Do not delete. Needed for Automation needs attention Delete label after triage labels Aug 22, 2024
@bgavrilMS bgavrilMS added this to the 4.64.0 milestone Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants