【发布时间】:2023-03-07 14:55:02
【问题描述】:
我正在尝试使用 RESTsharp 库对 RESTful 服务(sabre REST api)进行身份验证,但我无法对其进行身份验证。我正在使用我的客户 ID 和密码。请告诉我如何使用 oAuth 2.0 身份验证器进行身份验证。
我已经尝试过这段代码。 (saber 使用的是 OAuth 2.0 认证)
public ActionResult Index()
{
var client = new RestClient("https://api.test.sabre.com");
client.Authenticator = new HttpBasicAuthenticator("myclientid", "myclientsecret");
RestRequest request = new RestRequest("/v1/auth/token", Method.POST);
request.AddHeader("Authorization", "Basic " + client);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("grant_type", "client_credentials");
IRestResponse response = client.Execute(request);
var content = response.Content;
ViewBag.R = content;
return View();
}
我得到了这个结果
{"error":"invalid_client","error_description":"Credentials are missing or the syntax is not correct"}
请告诉我我做错了什么。 谢谢
显示了 Fiddler 运行代码(不使用 RestSharp)和使用 RestSharp 的代码比较的快照
使用 RestSharp
【问题讨论】:
标签: authentication oauth restsharp