Ausnahme 1: < /p>
Code: Select all
MsalClientException: An HttpListenerException occurred while listening on http://localhost:5267/ for the system browser to complete the login. Possible cause and mitigation: the app is unable to listen on the specified URL; run 'netsh http add iplisten 127.0.0.1' from the Admin command prompt.
< /code>
Ausnahme 2: < /p>
HttpListenerException: The process cannot access the file because it is being used by another process.
Code: Select all
string[] scopes = new string[] { "user.read" };
var tempUri = "https://login.microsoftonline.com/" + tenantId;
var app = PublicClientApplicationBuilder.Create(appId)
.WithAuthority(new Uri(tempUri))
.WithRedirectUri("http://localhost:5267/ezSearch/Main/Test")
.Build();
AuthenticationResult result;
string token = string.Empty;
try
{
var accounts = app.GetAccountsAsync().Result;
result = app.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
.ExecuteAsync().Result;
}
catch (AggregateException ex)
{
if (ex.InnerException is MsalUiRequiredException)
{
result = app.AcquireTokenInteractive(scopes)
.WithPrompt(Microsoft.Identity.Client.Prompt.NoPrompt)
.ExecuteAsync().Result; // Exceptions occur here
}
else
{
throw;
}
}
token = result.AccessToken;
Wie kann ich die httplistenerexception beheben, wenn ich accocireTokenInteractive ? http hinzufügen iplisten 127.0.0.1 "und recirecturl in Azure App Authentifizierung Seite
Alle Erkenntnisse oder Vorschläge wären sehr geschätzt. Danke!