使用RestSharp针对Bronto REST Api进行身份验证

时间:2019-05-07 06:55:12

标签: c# restsharp bronto

我已经在Bronto沙箱中设置了hallmonitor(OAuth 2.0兼容服务),但是使用RestSharp,我无法获得访问令牌以能够进一步调用REST API。

我已经能够成功使用curl

curl -X POST -d "grant_type=client_credentials&client_id=CLIENTID&client_secret=CLIENTSECRET" https://auth.bronto.com/oauth2/token 

我尝试了以下代码的多种变体,但似乎无济于事,我总是收到错误响应。

{
    "error_description": "Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method).",
    "error": "unauthorized_client"
}

简化的示例代码

var client = new RestClient("https://auth.bronto.com");
client.Authenticator = new HttpBasicAuthenticator(clientId, secret);
//client.Authenticator = new SimpleAuthenticator(CLIENT_ID, clientId, CLIENT_SECRET, secret);

RestRequest request = new RestRequest("/oauth2/token", Method.POST);
//request.AddHeader("Authorization", "Basic " + client);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter(GRANT_TYPE, CLIENT_CREDENTIALS);
//request.AddParameter(CLIENT_ID, clientId);
//request.AddParameter(CLIENT_SECRET, secret);

request.RequestFormat = DataFormat.Json;

IRestResponse response = client.Execute(request);

有人使用RestSharp和Bronto REST API来成功进行身份验证并获取访问令牌吗?

非常感谢您的帮助。

0 个答案:

没有答案