問題描述
從 AuthURL 和 ClientID 獲取 OAuth2.0 Bearer Token (Get OAuth2.0 Bearer Token from AuthURL and ClientID)
在 Postman 中,我可以使用
- Callback URL
- Auth URL
- Client ID 生成承載令牌ol>
如何使用 C# 代碼執行相同操作?
這是我正在運行的代碼,但響應正文沒有不記名令牌。
var client = new RestClient("AuthURL");
var requestToken = new RestRequest(Method.POST);
requestToken.AddHeader("cache‑control", "no‑cache");
requestToken.AddHeader("content‑type", "application/x‑www‑form‑urlencoded");
requestToken.AddParameter("application/x‑www‑form‑urlencoded", "grant_type=client_credentials&client_id=123", ParameterType.RequestBody);
IRestResponse response = client.Execute(requestToken);
string res = response.Content;
參考解法
方法 1:
where is your username and password?
var client = new RestClient("http://example.com");
client.Authenticator = new HttpBasicAuthenticator(userName, password);
var request = new RestRequest("resource", Method.GET);
client.Execute(request);
might be a duplicate of this question RestSharp HttpBasicAuthentication ‑ example
(by sreesh prakash、Fractal)