Hello,
I have created a Plugin to call REST API but while I am generating token it gives "401 Unauthorized" error in the result.
Below is the code I am using to generate the token. As soon as it goes to res, it throws an error.
private static async Task GetToken(string clientId, string clientSecret, string tokenBaseUrl)
{
using (var client = new HttpClient())
{
client.BaseAddress = new System.Uri(tokenBaseUrl);
try
{
var keysValues = new List<KeyValuePair>
{
new KeyValuePair("grant_type", "client_credentials"),
new KeyValuePair("client_id", clientId),
new KeyValuePair("clientSecret", clientSecret)
};
var res = await client.PostAsync("/ul/auth/oauth/v2/token", new FormUrlEncodedContent(keysValues));
return JsonConvert.DeserializeObject(await res.Content.ReadAsStringAsync()).access_token.Value;
}
catch(Exception e)
{
throw new Exception(e.Message);
}
}
}
In header the error is "x-ca-err: 300201"

However, I have tested my code in console app, it's working and also verified - client id, client secret, url - everything is correct.
Any help is really appreciated!!
Thank You!