- Home /
Window prompt not showing when using MSAL .NET library
I'm trying to log in to SharePoint with my Unity app via the MSAL library (Microsoft Identity Platform). When I run it the first time I don’t see a popup at all and there are no errors. (note, I've tried in Editor and as a standalone exe)
However, I did notice after running a second time, I get a popup window entitled Oops
with the message Could not register the window class win32 error 0
. After some googling I think it might be because there is some kind of dangling window in the background somewhere after the first attempt that I need to somehow clean up. If I restart Unity I can run again with the first time having no error but again no popup window. If I run a second time, of course, I again get the Oops
message.
Probably unrelated but worth noting is that if I hit “Ok” on the Oops
window I get a null exception error. It seems the AcquireTokenInteractive is trying to open a window which fails, leaving it null, and then tries to get the token from the null.
Any advice to help figure out why the window isn’t presenting would be greatly appreciated
using Microsoft.Identity.Client;
public class MyApp: MonoBehaviour
{
private string ClientId = "i-am-not-telling";
private string Tenant = "common";
void Start()
{
SharepointLogin();
}
public async void SharepointLogin()
{
PublicClientApp = PublicClientApplicationBuilder.Create(ClientId)
.WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
.WithAuthority(AzureCloudInstance.AzurePublic, Tenant)
.Build();
IEnumerable<string> scopes = new List<string> { "User.Read" };
AuthenticationResult result;
result = await PublicClientApp.AcquireTokenInteractive(scopes)
.ExecuteAsync();
}
}