[Bug] Unable to use WAM in Unity 2021
See original GitHub issueLogs 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:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
This should be fixed with our newer WAM implementation, see https://aka.ms/msal-net-wam
I ended up using Interactive - see here: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/2766#issuecomment-955578900