I am implementing MSAL in my windows application. i want to open a windows prompt to open to select the account.
when I hover on Prompt in code i see below error

The prompt does not open at all.
below is the code I am using
private async Task CallGraph()
{
var _clientApp = PublicClientApplicationBuilder.Create(id)
.WithAuthority(AzureCloudInstance.AzurePublic, "somevalue")
.WithDefaultRedirectUri()
.Build();
string[] scopes = new string[] { "user.read" };
AuthenticationResult authResult = null;
var app = _clientApp;
//ResultText.Text = string.Empty;
//TokenInfoText.Text = string.Empty;
var accounts = await app.GetAccountsAsync();
var firstAccount = accounts.FirstOrDefault();
try
{
authResult = await app.AcquireTokenSilent(scopes,
firstAccount)
.ExecuteAsync();
}
catch (MsalUiRequiredException ex)
{
// A MsalUiRequiredException happened on AcquireTokenSilent.
// This indicates you need to call AcquireTokenInteractive to acquire a token
System.Diagnostics.Debug.WriteLine($"MsalUiRequiredException: {ex.Message}");
try
{
authResult = await app.AcquireTokenInteractive(scopes)
//.WithUseEmbeddedWebView(false)
//.WithPrompt(Prompt.SelectAccount)
.ExecuteAsync();
}
catch (MsalException msalex)
{
TraceLogging.LogException($"Error Acquiring Token:{System.Environment.NewLine}{msalex}", ex);
}
}
catch (Exception ex)
{
TraceLogging.LogException($"Error Acquiring Token Silently:{System.Environment.NewLine}{ex}", ex);
return;
}
if (authResult != null)
{
await GetHttpContentWithToken(graphAPIEndpoint, authResult.AccessToken);
string res = $"Username: {authResult.Account.Username}" + Environment.NewLine;
//DisplayBasicTokenInfo(authResult);
//this.SignOutButton.Visibility =
Visibility.Visible;
}
}
public async Task<string> GetHttpContentWithToken(string url, string token)
{
var httpClient = new System.Net.Http.HttpClient();
System.Net.Http.HttpResponseMessage response;
try
{
var request = new
System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, url);
//Add the token in Authorization header
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
response = await httpClient.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();
return content;
}
catch (Exception ex)
{
return ex.ToString();
}
}
I want to implement msal for both desktop and web app .Please let me know for any more details or any sample application which uses asp .net and not dotnet core
I registered one Azure AD application by adding redirect URI in Mobile & Desktop applications platform and enabled public-client flow:
Now, I created one Windows Forms App(.NET Framework) and replaced the below files with following code:
Form1.cs:
Form1.Designer.cs:
When I ran the application now and clicked on Call Graph button, prompt came to pick an account like this:
While signing in, it asked me to consent the permissions with below screen:
After accepting the consent, I got the pop-up with signed-in user's Username successfully like this: