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] Broker-based flows fail for MSA accounts with latest MSAL #4696

Closed
localden opened this issue Apr 2, 2024 · 0 comments · Fixed by #4778
Closed

[Bug] Broker-based flows fail for MSA accounts with latest MSAL #4696

localden opened this issue Apr 2, 2024 · 0 comments · Fixed by #4778
Assignees
Labels
broker bug P1 public-client regression Behavior that worked in a previous release that no longer works in a newer release runtime scenario:Desktop

Comments

@localden
Copy link
Collaborator

localden commented Apr 2, 2024

Library version used

4.60.1

.NET version

6.0

Scenario

PublicClient - desktop app

Is this a new or an existing app?

This is a new app or experiment

Issue description and reproduction steps

Here is the sample code that I use:

var scopes = new[] { "User.Read" };

BrokerOptions options = new(BrokerOptions.OperatingSystems.Windows)
{
    Title = "My Awesome Application"
};

StorageCreationProperties storageProperties = new StorageCreationPropertiesBuilder("cache.bin", AppDomain.CurrentDomain.BaseDirectory).Build();

IPublicClientApplication app =
    PublicClientApplicationBuilder.Create("49e23d21-c709-47b5-b947-ad8e68455b14")
    .WithAuthority("https://login.microsoftonline.com/common")
    .WithDefaultRedirectUri()
    .WithParentActivityOrWindow(GetConsoleOrTerminalWindow)
    .WithBroker(options)
    .Build();

// This hooks up the cross-platform cache into MSAL
var cacheHelper = await MsalCacheHelper.CreateAsync(storageProperties);
cacheHelper.RegisterCache(app.UserTokenCache);

AuthenticationResult result = null;

// Try to use the previously signed-in account from the cache
IEnumerable<IAccount> accounts = await app.GetAccountsAsync();
IAccount existingAccount = accounts.FirstOrDefault();

try
{
    if (existingAccount != null)
    {
        result = await app.AcquireTokenSilent(scopes, existingAccount).ExecuteAsync();
    }
    // Next, try to sign in silently with the account that the user is signed into Windows
    else
    {
        result = await app.AcquireTokenSilent(scopes, PublicClientApplication.OperatingSystemAccount)
                            .ExecuteAsync();
    }
}
// Can't get a token silently, go interactive
catch (MsalUiRequiredException ex)
{
    result = await app.AcquireTokenInteractive(scopes).ExecuteAsync();
}

Console.WriteLine(result.AccessToken);

This worked in MSAL.NET 4.59.0, but upon upgrading to 4.60.1 I am now getting this error:

Screenshot of the error produced in Visual Studio for the broker-based flow

Keep in mind that the account was already selected (MSA account which is secondary on the OS) and then the error pops up. The code worked OK in MSAL 4.59.0.

Relevant code snippets

No response

Expected behavior

Broker-based flow goes through.

Identity provider

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

Regression

4.59.0

Solution and workarounds

None. Downgrade MSAL to 4.59.0.

@localden localden added broker runtime untriaged Do not delete. Needed for Automation needs attention Delete label after triage public-client regression Behavior that worked in a previous release that no longer works in a newer release labels Apr 2, 2024
@gladjohn gladjohn added bug P1 regression Behavior that worked in a previous release that no longer works in a newer release scenario:Desktop and removed regression Behavior that worked in a previous release that no longer works in a newer release untriaged Do not delete. Needed for Automation needs attention Delete label after triage labels Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broker bug P1 public-client regression Behavior that worked in a previous release that no longer works in a newer release runtime scenario:Desktop
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants