【问题标题】:Get OAuth2.0 Bearer Token from AuthURL and ClientID从 Auth URL 和 Client ID 获取 OAuth 2.0 Bearer Token
【发布时间】:2020-11-12 16:59:04
【问题描述】:

在 Postman 中,我可以使用

生成承载令牌
  1. 回调网址
  2. 授权网址
  3. 客户 ID

如何使用 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;

【问题讨论】:

  • 响应包含什么?可能是某种错误?
  • 请求成功但响应没有承载令牌。

标签: c# rest oauth postman bearer-token


【解决方案1】:

您的用户名和密码在哪里?

var client = new RestClient("http://example.com");
client.Authenticator = new HttpBasicAuthenticator(userName, password);

var request = new RestRequest("resource", Method.GET);
client.Execute(request);

可能与此问题重复 RestSharp HttpBasicAuthentication - example

【讨论】:

    猜你喜欢
    • 2014-01-02
    • 2014-11-08
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-31
    相关资源
    最近更新 更多