I keep getting 400 bad request, but when using postman I am able to generate the token.
When checking in fiddler i see the credential passing in {"key":"value", "key":value"}
but when sending the request in postman the credentials are passing like so key=value,key=value,
Also I think I have to add Authentication type Basic how do I do that?
[![enter image description here][1]][1]
[![enter image description here][2]][2]
Here is my Test method
[Test]
[Obsolete]
public void AuthenticationMechanism()
{
var client = new RestClient("http://examplegeneratetoken.com/");
var request = new RestRequest("connect/token", Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("cache-Control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddHeader("content-ecoding", "gzip");
request.AddBody(new {grant_type="password",username="exampleabc@email.com",password="pass",scope="abc",client_id="postapi",client_secret="abc123"});
var response = client.ExecutePostTaskAsync(request).GetAwaiter().GetResult();
var access_token = response.DeserializeResponse()["access_token"];
}
Here is my deserilization method
public static class Libraries
{
public static Dictionary<string, string> DeserializeResponse(this IRestResponse restResponse)
{
var JSONObj = new JsonDeserializer().Deserialize<Dictionary<string, string>>(restResponse);
return JSONObj;
}
}
[1]: https://i.stack.imgur.com/zJLEA.png
[2]: https://i.stack.imgur.com/HQn3o.png