On multiple machines, I am having no problem, however, on one machine (Win 10, x64) I'm getting the following error:
Null user was passed in AcquiretokenSilent API.
Pass in a user object or call acquireToken authenticate.
The code is the basic MSAL code and I'm using the MSGraph API. The program "hangs" on the following line:
authResult = await App.PublicClientApp.AcquireTokenAsync(scopes);
Here is the complete method:
private async void SignInButton_Click(object sender, RoutedEventArgs e)
{
// StatusMsg.Text = string.Empty;
try
{
authResult = await App.PublicClientApp.AcquireTokenSilentAsync(scopes, App.PublicClientApp.Users.FirstOrDefault());
StatusMsg.Text = "Success Logging In";
}
catch (MsalUiRequiredException ex)
{
// A MsalUiRequiredException happened on AcquireTokenSilentAsync. This indicates you need to call AcquireTokenAsync to acquire a token
System.Diagnostics.Debug.WriteLine($"MsalUiRequiredException: {ex.Message}");
try
{
authResult = await App.PublicClientApp.AcquireTokenAsync(scopes);
StatusMsg.Text = "Success Logging In with Scopes";
}
catch (MsalException msalex)
{
StatusMsg.Text = $"Error Acquiring Token:{System.Environment.NewLine}{msalex}";
}
}
catch (Exception ex)
{
StatusMsg.Text = $"Error Acquiring Token Silently:{System.Environment.NewLine}{ex}";
return;
}
if (authResult != null)
{
StatusMsg.Text = "Signed In ";
StatusMsg.Text += $"Name: {authResult.User.Name}" + Environment.NewLine;
StatusMsg.Text += $"Username: {authResult.User.DisplayableId}" + Environment.NewLine;
StatusMsg.Text += $"Token Expires: {authResult.ExpiresOn.ToLocalTime()}" + Environment.NewLine;
//StatusMsg.Text += "NotebookName/ID = " + Globals.CurentNotebookName.ToString() + " / " + Globals.CurrentNotebookId.ToString() + Environment.NewLine;
}
}
Here is my autho and scopes:
private AuthenticationResult authResult = null;
private string[] scopes = { "Notes.ReadWrite" };