RestSharp Oauth2 authentication Cherwell restful api
<p>I normally don't ask questions here because most of the times I can find answers. But at this moment I haven´t find one, and I am really stuck. I have a problem trying to get access token for the Cherwell api: <a href="http://13.88.176.216/CherwellAPI/Swagger/ui/index#!/Service/Service_Token" rel="nofollow">http://13.88.176.216/CherwellAPI/Swagger/ui/index#!/Service/Service_Token</a> I used postman to generate this code:</p>

<p>This is relevant to Cherwell Service Management's V8+ REST API.</p>

<p>Code that throws server run time exception:</p>

<pre><code> string user = "myUser";
    string password = "myPassword";

    var client1 = new RestClient("http://13.88.176.216/cherwellapi/token?auth_mode=Internal");
client.Authenticator = new HttpBasicAuthenticator(user, password);
    var request1 = new RestRequest(Method.POST);
    request1.AddHeader("content-type", "application/x-www-form-urlencoded");

    request1.AddHeader("cache-control", "no-cache");
    request1.AddParameter("application/x-www-form-urlencoded", "grant_type=password&amp;client_id=my_client_id&amp;client_secret=my_client_secret", ParameterType.RequestBody);
    IRestResponse response = client1.Execute(request1);
</code></pre>

<p>The thing is when I execute the same method from the swagger ui (<a href="http://13.88.176.216/CherwellAPI/Swagger/ui/index#!/Service/Service_Token" rel="nofollow">http://13.88.176.216/CherwellAPI/Swagger/ui/index#!/Service/Service_Token</a>) I can get the token without getting any error. </p>

<p>Details of the request in CURL:</p>

<p>Curl</p>

<p>curl -X POST 
--header "Content-Type: application/x-www-form-urlencoded" 
--header "Accept: application/json" -d "grant_type=password&amp;client_id=my_client_id&amp;client_secret=my_client_secret&amp;username=my_user_name&amp;password=my_password" "<a href="http://13.88.176.216/CherwellAPI/token?auth_mode=Internal" rel="nofollow">http://13.88.176.216/CherwellAPI/token?auth_mode=Internal</a>"</p>

<p>Request URL
<a href="http://13.88.176.216/CherwellAPI/token?auth_mode=Internal" rel="nofollow">http://13.88.176.216/CherwellAPI/token?auth_mode=Internal</a></p>

<p>This is the response body from the swagger ui test, not my code:</p>

<pre><code>{
  "access_token": "the_acces_token",
  "token_type": "bearer",
  "expires_in": 1199,
  "refresh_token": "the_refresh_token",
  "as:client_id": "client_key",
  "username": "user",
  ".issued": "date",
  ".expires": "other_date"
}
</code></pre>

<p>Any help will be appreciated.</p>