[Bug] Interactive flow not working 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)
.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.
NotImplementedException: The method or operation is not implemented.
System.Runtime.InteropServices.Marshal.ReadInt16 (System.Object ptr, System.Int32 ofs) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Drawing.Font.FromLogFont (System.Object lf, System.IntPtr hdc) (at <1e9166bfca654377b09cea42d003812d>:0)
System.Drawing.Font.FromHfont (System.IntPtr hfont) (at <1e9166bfca654377b09cea42d003812d>:0)
System.Drawing.SystemFonts.get_DefaultFont () (at <1e9166bfca654377b09cea42d003812d>:0)
System.Windows.Forms.Control.get_DefaultFont () (at <3b28f5500d544e019e30dca09fab36d7>:0)
System.Windows.Forms.Control.get_Font () (at <3b28f5500d544e019e30dca09fab36d7>:0)
System.Windows.Forms.WebBrowserBase.get_Font () (at <3b28f5500d544e019e30dca09fab36d7>:0)
System.Windows.Forms.Control.AssignParent (System.Windows.Forms.Control value) (at <3b28f5500d544e019e30dca09fab36d7>:0)
System.Windows.Forms.Control+ControlCollection.Add (System.Windows.Forms.Control value) (at <3b28f5500d544e019e30dca09fab36d7>:0)
Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WindowsFormsWebAuthenticationDialogBase.<InitializeComponent>b__32_0 () (at <f4fac412be4346e4bdfeff1f81897b10>:0)
Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WindowsFormsWebAuthenticationDialogBase.InvokeHandlingOwnerWindow (System.Action action) (at <f4fac412be4346e4bdfeff1f81897b10>:0)
Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WindowsFormsWebAuthenticationDialogBase.InitializeComponent () (at <f4fac412be4346e4bdfeff1f81897b10>:0)
Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WindowsFormsWebAuthenticationDialogBase…ctor (System.Object ownerWindow) (at <f4fac412be4346e4bdfeff1f81897b10>:0)
Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WindowsFormsWebAuthenticationDialog…ctor (System.Object ownerWindow) (at <f4fac412be4346e4bdfeff1f81897b10>:0)
(wrapper remoting-invoke-with-check) Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WindowsFormsWebAuthenticationDialog…ctor(object)
Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.InteractiveWebUI.OnAuthenticate () (at <f4fac412be4346e4bdfeff1f81897b10>:0)
Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WebUI.Authenticate (System.Uri requestUri, System.Uri callbackUri) (at <f4fac412be4346e4bdfeff1f81897b10>:0)
Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WebUI+<>c__DisplayClass20_0.<AcquireAuthorizationAsync>b__1 (System.Object tcs) (at <f4fac412be4346e4bdfeff1f81897b10>:0)
— End of stack trace from previous location where exception was thrown —
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0) Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WebUI+<AcquireAuthorizationAsync>d__20.MoveNext () (at <f4fac412be4346e4bdfeff1f81897b10>:0) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1+ConfiguredTaskAwaiter[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
Microsoft.Identity.Client.Internal.AuthCodeRequestComponent+<FetchAuthCodeAndPkceInternalAsync>d__7.MoveNext () (at <f4fac412be4346e4bdfeff1f81897b10>:0)
— End of stack trace from previous location where exception was thrown —
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0) Microsoft.Identity.Client.Internal.AuthCodeRequestComponent+<FetchAuthCodeAndPkceVerifierAsync>d__4.MoveNext () (at <f4fac412be4346e4bdfeff1f81897b10>:0) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1+ConfiguredTaskAwaiter[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
Microsoft.Identity.Client.Internal.Requests.InteractiveRequest+<GetTokenResponseAsync>d__11.MoveNext () (at <f4fac412be4346e4bdfeff1f81897b10>:0)
— End of stack trace from previous location where exception was thrown —
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0) Microsoft.Identity.Client.Internal.Requests.InteractiveRequest+<ExecuteAsync>d__8.MoveNext () (at <f4fac412be4346e4bdfeff1f81897b10>:0) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1+ConfiguredTaskAwaiter[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
Microsoft.Identity.Client.Internal.Requests.RequestBase+<RunAsync>d__12.MoveNext () (at <f4fac412be4346e4bdfeff1f81897b10>:0)
— End of stack trace from previous location where exception was thrown —
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0) Microsoft.Identity.Client.ApiConfig.Executors.PublicClientExecutor+<ExecuteAsync>d__2.MoveNext () (at <f4fac412be4346e4bdfeff1f81897b10>:0) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter
1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
UCB.XR.Virtu.Services.Security.AuthenticationService+<GetIntegratedWindowsAuthenticationResultAsync>d__0.MoveNext () (at Assets/Scripts/UCB/XR/Services/Security/AuthenticationService.cs:41)
— End of stack trace from previous location where exception was thrown —
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
UCB.XR.Virtu.Security.AuthenticationManager+<Start>d__0.MoveNext () (at Assets/Scripts/XR/Security/AuthenticationManager.cs:11)
— End of stack trace from previous location where exception was thrown —
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <adfa4b62400849189388df71c9e26e89>:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
@bgavrilMS Thanks for the tip, worked great. Sharing my findings here, might help someone else. These works for a standalone windows build using Unity 2019.4.
@juanworkobot - you can add a custom message or a custom redirect instead of the default Authentication complete. You can return to the application. Feel free to close this browser tab."
See https://learn.microsoft.com/en-us/dotnet/api/microsoft.identity.client.acquiretokeninteractiveparameterbuilder.withsystemwebviewoptions?view=azure-dotnet