Я пытаюсь получить токен с именем пользователя и паролем, но аутентификация вызывает исключение, и токен имеет значение NULL. Я довольно новичок в Azure. Мой код:
public string AuthenticateUser(string username, string password)
{
const string resources = "https://management.core.windows.net/";
const string clientId = "";
const string aadTokenIssuerUri = "https://login.windows.net/common/";
AuthenticationContext authenticationContext = new AuthenticationContext(aadTokenIssuerUri);
UserCredential userCredentials = new UserPasswordCredential(username, password);
if (authenticationContext.TokenCache != null)
{
authenticationContext.TokenCache.Clear();
}
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(
resources,
clientId,
userCredentials).GetAwaiter().GetResult();
var token = authenticationResult.AccessToken;
return token;
}
try
{
var token = azureUsers.AuthenticateUser("", "");
if (!string.IsNullOrEmpty(token))
{
Console.WriteLine("here is token {0}", token);
result = true;
}
}
catch (Exception e)
{
if (i < numRetries)
{
Thread.Sleep(retryInterval);
}
}
Скажите, пожалуйста, что не так с этим кодом.