简体   繁体   English

从 AuthURL 和 ClientID 获取 OAuth2.0 Bearer Token

[英]Get OAuth2.0 Bearer Token from AuthURL and ClientID

In Postman I am able to generate the Bearer token using在 Postman 我可以使用生成不记名令牌

  1. Callback URL回调 URL
  2. Auth URL授权URL
  3. Client ID客户编号

How do I do the same using C# code?如何使用 C# 代码做同样的事情?

This is the code I am running but the response body does not have the bearer token.这是我正在运行的代码,但响应正文没有不记名令牌。

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;

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可能是这个问题RestSharp HttpBasicAuthentication - example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM