question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Unable to use WAM in Unity 2021

See original GitHub issue

Logs and network traces None

Which version of MSAL.NET are you using? 4.34 - the Microsoft.Identity.Client.dll is added as a Unity plugin (for Editor and Standalone only)

Platform .NET 4.5, Unity 2021

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive
    • Integrated Windows Authentication
    • Username Password
    • Device code flow (browserless)
  • Web app
    • Authorization code
    • On-Behalf-Of
  • Daemon app
    • Service to Service calls

Is this a new or existing app? This is a new app or experiment.

Repro

            string[] scopes = new string[] { "user.read" };

            var app = PublicClientApplicationBuilder
                         .Create(Preferences.ClientId)
                         .WithTenantId(Preferences.TenantId)
                         .WithBroker()
                         .WithWindowsBrokerOptions(new WindowsBrokerOptions() { ListWindowsWorkAndSchoolAccounts = true, MsaPassthrough = true })
                         .WithLogging(MyLoggingMethod, LogLevel.Info,
                           enablePiiLogging: true,
                           enableDefaultPlatformLogging: true)
                         .Build();

            var accounts = await app.GetAccountsAsync();

            AuthenticationResult result = null;
            if (accounts.Any())
            {
                result = await app.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
                                    .ExecuteAsync();
            }
            else
            {
                try
                {
                    result = await app.AcquireTokenInteractive(scopes)
                                        .ExecuteAsync(CancellationToken.None);
                }
                catch (MsalUiRequiredException ex)
                { }
            }

Expected behavior The login popup appears or account is detected.

Actual behavior Errors appear in the log - nothing happens.

Assembly ‘Assets/Plugins/MSAL/Microsoft.Identity.Client.Desktop.dll’ will not be loaded due to errors: Unable to resolve reference ‘Windows.Foundation.FoundationContract’. Is the assembly missing or incompatible with the current platform? Reference validation can be disabled in the Plugin Inspector. Unable to resolve reference ‘Windows.Foundation.UniversalApiContract’. Is the assembly missing or incompatible with the current platform? Reference validation can be disabled in the Plugin Inspector. Unable to resolve reference ‘System.Runtime.WindowsRuntime’. Is the assembly missing or incompatible with the current platform? Reference validation can be disabled in the Plugin Inspector.

If I disable Validate references I get this:

Error: Could not load signature of Microsoft.Identity.Client.Platforms.WebAuthenticationCoreManagerInterop:RequestTokenForWindowAsync due to: Could not load file or assembly ‘Windows.Foundation.FoundationContract, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. assembly:Windows.Foundation.FoundationContract, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:(null) signature:<none>

PlatformNotSupportedException: The Windows broker is not directly available on MSAL for .NET Framework To use it, please install the nuget package named Microsoft.Identity.Client.Desktop and call the extension method .WithWindowsBroker() first. Microsoft.Identity.Client.PublicClientApplicationBuilder.WithBroker (System.Boolean enableBroker) (at <f4fac412be4346e4bdfeff1f81897b10>:0)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bgavrilMScommented, Aug 25, 2022

This should be fixed with our newer WAM implementation, see https://aka.ms/msal-net-wam

1reaction
eusebiucommented, Jan 19, 2022

@eusebiu I see this is from some time ago. Did you get to find any workaround for the issue?

I ended up using Interactive - see here: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/2766#issuecomment-955578900

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug - Can't build for Android
Latest Hub 3.2.0 in combination with Unity 2021.3.6 can't build for Android because there is a missing Tools folder inside...
Read more >
Texture is not readable unity. … The material I created with
I can't use TextureImporter or AssetDatabase. Load<Texture2D> (name)); Dubble check what is the name of the texture in the shader. However, I noticed...
Read more >
Anyone else thinks Unity 2022 is a huge mess? : r/Unity3D
Several times I tried to use the 2022 version of Unity. ... Unable to build Games in 2022, but in 2021 it works...
Read more >
Unity setactive performance. Making a GameObject inactive ...
Unity setactive performance. Making a GameObject inactive will disable every component, turning off any attached renderers, colliders, rigidbodies, scripts, ...
Read more >
How do I resolve Duo user login issues in Office 365 ...
There are generally two problems we see WAM causing: Users are unable to authenticate (particularly after a password reset); Users are being prompted...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found