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] Unable to use WAM in Unity 2021 #2765

Closed
2 of 7 tasks
eusebiu opened this issue Jul 14, 2021 · 7 comments
Closed
2 of 7 tasks

[Bug] Unable to use WAM in Unity 2021 #2765

eusebiu opened this issue Jul 14, 2021 · 7 comments
Labels

Comments

@eusebiu
Copy link

eusebiu commented Jul 14, 2021

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: member:(null) signature:

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 :0)

@bgavrilMS
Copy link
Member

@eusebiu - MSAL needs to call WAM via Windows API (COM) invocation. To do this, we had to add a reference to https://www.nuget.org/packages/Microsoft.Windows.SDK.Contracts/10.0.17763.1000 which provides these APIs.

Can you consume this package directly in a Unity project? If not, we should follow up with the respective team. I am not sure they plan on supporting Mono.

@eusebiu
Copy link
Author

eusebiu commented Jul 23, 2021

After installing the Desktop package using NuGet for Unity (which installs the dependencies too), I still get errors:
Assembly 'Assets/Packages/Microsoft.Web.WebView2.1.0.705.50/lib/net45/Microsoft.Web.WebView2.Wpf.dll' will not be loaded due to errors:
Unable to resolve reference 'PresentationFramework'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'PresentationCore'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.

Assembly 'Assets/Packages/Microsoft.Identity.Client.Desktop.4.34.0/lib/net461/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.

@vaoliva
Copy link

vaoliva commented Jan 19, 2022

Hitting the same issue here when trying to enable WAM use with MSAL in Unity. Do we have any updates or workarounds on that issue?

@vaoliva
Copy link

vaoliva commented Jan 19, 2022

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

@bgavrilMS
Copy link
Member

We don't have any updates on the issue. We are exploring a different mechanism to call into WAM, but don't have an ETA.

@vaoliva - do you need to support both AAD and MSA accounts? Can you call WAM directly instead of through MSAL? This sample shows how you can do it for AAD accounts, but should be similar for MSA accounts:

https://github.com/azure-samples/active-directory-dotnet-native-uwp-wam

@eusebiu
Copy link
Author

eusebiu commented 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: #2766 (comment)

@bgavrilMS
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants