microsoft-authentication-library-for-dotnet icon indicating copy to clipboard operation
microsoft-authentication-library-for-dotnet copied to clipboard

[Bug] MSAL.net 4.42 fails on Windows Desktop Unity il2cpp build

Open ferretnt opened this issue 3 years ago • 3 comments

Logs and network traces Without logs or traces, it is unlikely that the team can investigate your issue. Capturing logs and network traces is described in Logging wiki.

Which version of MSAL.NET are you using? 4.42.0

Platform Unity 2021.2.12 Win64 Desktop build with il2cpp

What authentication flow has the issue?

  • Desktop / Mobile
    • [*] Interactive

Is this a new or existing app?

Repro

  • Build any simple MSAL.net unity application that executes approximately this code (it's actually originally from the MSAL.net basic tutorial/demo, but with UseEmbeddedWebView(false). Use the .net461 DLL of msal.net 4.42.

  • Run the application in the Editor or as a Mono-based standalone player and observe correct execution.

  • Run the app as an il2cpp desktop app, and observe that some types have been stripped.

  • Fix those by adding recommended link.xml as follows:

  • Observe that il2cpp build still does not work with callstack given below.

      var builder = PublicClientApplicationBuilder.Create(ClientId)
              .WithAuthority($"{Instance}{Tenant}")
              .WithRedirectUri("http://localhost");
    
      _clientApp = builder.Build();
    
      try
      {
          redirectToBrowserTextMesh.gameObject.SetActive(true);
    
          authResult = await _clientApp.AcquireTokenInteractive(scopes)
               .WithUseEmbeddedWebView(false)
               .WithPrompt(Prompt.SelectAccount)
               .ExecuteAsync();
    

Expected behavior We expect il2cpp to behave identically to desktop.

Actual behavior Exception thrown, top lines of callstack shown below:

at System.Diagnostics.Process.StartWithShellExecuteEx (System.Diagnostics.ProcessStartInfo startInfo) [0x00000] in <00000000000000000000000000000000>:0 at System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo) [0x00000] in <00000000000000000000000000000000>:0 at Microsoft.Identity.Client.Platforms.net45.NetDesktopPlatformProxy.StartDefaultOsBrowserAsync (System.String url, System.Boolean isBrokerConfigured) [0x00000] in <00000000000000000000000000000000>:0 at Microsoft.Identity.Client.Platforms.Shared.Desktop.OsBrowser.DefaultOsBrowserWebUi.InterceptAuthorizationUriAsync (System.Uri authorizationUri, System.Uri redirectUri, System.Boolean isBrokerConfigured, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 at Microsoft.Identity.Client.Platforms.Shared.Desktop.OsBrowser.DefaultOsBrowserWebUi.AcquireAuthorizationAsync (System.Uri authorizationUri, System.Uri redirectUri, Microsoft.Identity.Client.Internal.RequestContext requestContext, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 at Microsoft.Identity.Client.Platforms.Shared.Desktop.OsBrowser.DefaultOsBrowserWebUi.AcquireAuthorizationAsync (System.Uri authorizationUri, System.Uri redirectUri, Microsoft.Identity.Client.Internal.RequestContext requestContext, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 at Microsoft.Identity.Client.Internal.AuthCodeRequestComponent.FetchAuthCodeAndPkceInternalAsync (Microsoft.Identity.Client.UI.IWebUI webUi, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 at Microsoft.Identity.Client.Internal.AuthCodeRequestComponent.FetchAuthCodeAndPkceVerifierAsync (System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 at Microsoft.Identity.Client.Internal.AuthCodeRequestComponent.FetchAuthCodeAndPkceVerifierAsync (System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.GetTokenResponseAsync (System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0

Possible solution

Additional context / logs / screenshots / links to code

Add any other context about the problem here, such as logs and screenshots, and even links to code.

ferretnt avatar Mar 11 '22 00:03 ferretnt

This a known limitation and the team does not have resources to fix Unity / Mono setups . We would welcome a contribution.

Or consider using a UWP style of app instead.

bgavrilMS avatar Mar 11 '22 08:03 bgavrilMS

Thanks for the quick reply Bogdan. Sometimes knowing something isn’t supported is valuable and saves wasting time banging your head and wondering so appreciate this.

UWP (outside of HoloLens) has low support from other channels and I will probably look at implementing Oauth with UnityWebRequest rest calls instead. If you know of any examples already doing this to point to that would be much appreciated.

ferretnt avatar Mar 12 '22 17:03 ferretnt

This should now work with the latest WAM implementation, https://aka.ms/msal-net-wam

bgavrilMS avatar Aug 25 '22 11:08 bgavrilMS