Hi,
Im using KeyCloak Rest API and retrieving the token as below.
var result = await url
.AppendPathSegment($"/auth/realms/{realm}/protocol/openid-connect/token")
.WithHeader(“Accept”, “application/json”)
.PostUrlEncodedAsync(new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>(“grant_type”, “password”),
new KeyValuePair<string, string>(“username”, userName),
new KeyValuePair<string, string>(“password”, password),
new KeyValuePair<string, string>(“client_id”, “admin-cli”)
})
.ReceiveJson();
Token may be expired (90% this could be the reason) , try to increase the validity of token and try again, you can do that under Realm Settings > Tokens > Access token lifespan