I'm trying to authenticate with MSAL library. What is the purpose of "object parent" in the function call? Best I found was it's supposed to be the parent Window. I've tried putting this
(dumb, I know) and I've tried FindWindow(null, "AppName")
(from user32.dll) to get an IntPtr to the window of the app, but everything yields a null error when calling the function. So what should go there to enable this function to work? Does Unity have a specific handle to whatever this should be?
And why in the world do the docs not at all mention this required parent?? https://learn.microsoft.com/en-us/dotnet/api/microsoft.identity.client.ipublicclientapplication.acquiretokeninteractive?view=azure-dotnet
Edit: I was mostly concerned with what the "object parent" is supposed to be. Without knowing what it's supposed to be, I don't know how to call the function. As seen in the image below, Visual Studio is flagging the call without it and forcing me to put it in. I am now including the rest of the code in case someone wishes to point out something else entirely that I may be doing wrong apart from the question regarding the use of "parent".
using Microsoft.Identity.Client;
public async void SharepointLogin()
{
IntPtr windowPtr = FindWindow(null, "MyAppName"); // This is the "parent" object that I have no idea what it's supposed to be as it is not documented.
IPublicClientApplication PublicClientApp;
Debug.Log("Creating PublicClientApplicationBuilder");
PublicClientApp = PublicClientApplicationBuilder.Create(ClientId)
.WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
.WithAuthority(AzureCloudInstance.AzurePublic, Tenant)
.Build();
Debug.Log("Getting Accounts");
var accounts = await PublicClientApp.GetAccountsAsync();
IEnumerable<string> scopes = new List<string> { "User.Read" };
AuthenticationResult result;
try
{
Debug.Log("Trying Silent Token");
result = await PublicClientApp.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
.ExecuteAsync();
}
catch (MsalUiRequiredException)
{
Debug.Log("Failed. Trying Interactive Token");
// This is the line where I can't remove the "parent" object
// (in this case "windowPtr") without the error seen in the image
// below. It has no compile problems like this but it always has a
// null pointer exception when it runs. Everything is the same in the
// first "Try" except this "parent" object I'm forced to supply.
result = await PublicClientApp.AcquireTokenInteractive(scopes, windowPtr)
.ExecuteAsync();
}
}