See RFC 6749 – 4.4.2. Client Credentials – Access Token Request
Here is the basic format of the request
POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
Your cURL request
curl -H "Accept: application/json" \
-d grant_type=client_credentials \
client-app:[email protected]/myapi/oauth/token
The reason your cURL command works
-
Default
Content-Type
(if not specified) with POST (default when you use-d
switch) isapplication/x-www-form-urlencoded
-
Default authentication type, if not specified, is Basic. The username and password are passed either through the
-u
option or in the URL-u username:password (client-app:secret) -- or put it in the url -- client-app:[email protected]/myapi/oauth/token
You could also specify the auth type with
--basic
or--digest
You can use the -v
switch in your cURL command to see all the headers involved in the request.
RestSharp fix:
-
Set the
Content-Type
toapplication/x-www-form-urlencoded
-
Add the Basic authentication
client.Authenticator = new HttpBasicAuthenticator("client-app", "secret");
-
Get rid of
request.AddParameter("client_id", "client-app"); request.AddParameter("client_secret", "secret");
-
Set the
Accept
header toapplication/json