Hi @Siddartha Pal ,
Thanks for reaching out and apologies for the delay in response.
The error message "No account or login hint was passed to the AcquireTokenSilent call" indicates that the user is not authenticated, or the token cache is empty.
If you want to acquire a token silently, you need to ensure that the user is already authenticated and that the token cache is not empty. AcquireTokenSilent() attempts to acquire an access token for the account
from the user token cache.
The recommended pattern is to call the AcquireTokenSilent
method first and if it fails with a MsalUiRequiredException
, then acquires a token interactively using AcquireTokenInteractive().
AuthenticationResult result = null;
try
{
result = await app.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
.ExecuteAsync();
}
catch (MsalUiRequiredException ex)
{
// A MsalUiRequiredException happened on AcquireTokenSilent.
// This indicates you need to call AcquireTokenInteractive to acquire a token
Debug.WriteLine($"MsalUiRequiredException: {ex.Message}");
try
{
result = await app.AcquireTokenInteractive(scopes)
.ExecuteAsync();
}
catch (MsalException msalex)
{
ResultText.Text = $"Error Acquiring Token:{System.Environment.NewLine}{msalex}";
}
}
catch (Exception ex)
{
ResultText.Text = $"Error Acquiring Token Silently:{System.Environment.NewLine}{ex}";
return;
}
if (result != null)
{
string accessToken = result.AccessToken;
// Use the token
}
However, for confidential client applications called the AcquireTokenForClient(), it does not use the user token cache, but an application token cache. This method takes care of verifying this application token cache before sending a request.
Hope this will help.
Thanks,
Shweta
Please remember to "Accept Answer" if answer helped you.