Suddenly I got an error when getting a token to access SharePoint from the azure ad.
private async Task<string> AcquireTokenAsync(Uri resourceUri, string username, string password)
{
string resource = $"{resourceUri.Scheme}://{resourceUri.DnsSafeHost}";
var clientId = defaultAADAppId;
var body = $"resource={resource}&client_id={clientId}&grant_type=password&username={HttpUtility.UrlEncode(username)}&password={HttpUtility.UrlEncode(password)}";
using (var stringContent = new StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded"))
{
var result = await httpClient.PostAsync(tokenEndpoint, stringContent).ContinueWith((response) =>
{
return response.Result.Content.ReadAsStringAsync().Result;
}).ConfigureAwait(false);
var tokenResult = JsonSerializer.Deserialize<JsonElement>(result);
var token = tokenResult.GetProperty("access_token").GetString();
return token;
}
}
ValueKind = Object : "{"error":"interaction_required","error_description":"AADSTS530031: Access policy does not allow token issuance.\r\nTrace ID: 823cd416-a194-41b9-a7f7-3b00c33aca00\r\nCorrelation ID: 4c304826-338b-46d7-986c-f7cc5d78820a\r\nTimestamp: 2022-03-10 11:50:20Z","error_codes":[530031],"timestamp":"2022-03-10 11:50:20Z","trace_id":"823cd416-a194-41b9-a7f7-3b00c33aca00","correlation_id":"4c304826-338b-46d7-986c-f7cc5d78820a","error_uri":"https://login.microsoftonline.com/error?code=530031","suberror":"message_only"}"
This is the token result I got. This was working perfectly.Can someone help me to figure this out?