Исключение 1: < /p>
Код: Выделить всё
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>
Исключение 2: < /p>
HttpListenerException: The process cannot access the file because it is being used by another process.
Код: Выделить всё
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;
Как я могу разрешить httplistenerexception при использовании AccureTokenInteractive ? http Добавить iplisten 127.0.0.1 "и добавить redirecturl в странице аутентификации Azure App
Любое понимание или предложения были бы очень оценены. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/793 ... sal-and-sa