Hello @Jai Holloway ,
Thanks for your question.
In your SignInUserInteractivelyAsync method, you have this line:
.WithParentActivityOrWindow(new MainPage(...)).
You may want to avoid using new MainPage() here. That creates a brand-new, invisible screen in the background. The Microsoft login popup needs to attach to the actual, active screen the user is currently looking at. Because it tries to attach to an invisible screen, the app gets confused and crashes.
Also, when your silent login fails, it drops down to the catch (MsalUiRequiredException ex) block, but you are not passing the existingUser into the interactive method. This means the app forgets who is trying to log in.
You can refer to these following steps:
- In your
catch block, please make sure to pass the user context:
catch (MsalUiRequiredException ex)
{
Debug.WriteLine($"MsalUiRequiredException: {ex.Message}");
this.AuthResult = await this.SignInUserInteractivelyAsync(scopes, existingUser);
}
- In your
SignInUserInteractivelyAsync method, please do not create a new page. Point it to the actual active window:
#else
return await this.PublicClientApplication.AcquireTokenInteractive(scopes)
.WithLoginHint(existingAccount?.Username ?? String.Empty)
.WithUseEmbeddedWebView(true)
.WithParentActivityOrWindow(PlatformConfig.Instance.ParentWindow)
.ExecuteAsync()
.ConfigureAwait(false);
#endif
Please check and let me know how it goes. If you encounter any issues, I'll be happy to assist further.
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback. Thank you.