从DocuSign API请求访问令牌时收到400错误的请求消息
我可以通过使用链接 https://developers.docusign来生成docusign网站的访问令牌.com / oauth-token-generator
但是,当尝试使用c#代码在我们的系统中获取访问令牌时,却收到消息(远程服务器返回了错误:(400)错误的请求。)
But when try to get access token in our system using c# code then getting message (The remote server returned an error: (400) Bad Request.)
我遵循以下链接中提到的身份验证过程。
I follow the authenticate process mentioned in below link.
https://developers.docusign.com/esign-rest- api / guides / authentication / oauth2-code-grant
我能够获取验证码。我使用了此身份验证代码来访问API( https://account-d.docusign.com/oauth / token )。
I able to get authentication code. I used this authentication code to hit API (https://account-d.docusign.com/oauth/token).
下面是我的代码示例
string integrationKey = "key removed";
string secretKey = "key removed";
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://account-d.docusign.com/oauth/token");
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Method = "POST";
string apiStoreConsumer = "removed";
httpWebRequest.Headers.Add("Authorization", "Basic " + apiStoreConsumer);
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string input = "authorization_code&authorization_code= <authentication code goes here>;
streamWriter.Write(input);
streamWriter.Flush();
streamWriter.Close();
}
WebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
查询:
为什么会出现400错误?
我们是否有访问令牌的到期时间,如果是,那么需要多长时间?
身份验证代码是否对每个请求都有效?
Why am I getting 400 error? Do we have any expiry time for access token, if yes then how long? Does authentication code get change for every request?
请帮助我。
谢谢!
我建议您在.NET / C#中使用OAuth库
如果您想了解操作方法,请克隆此仓库。
问题是您需要首先获取代码,然后进行交换e作为令牌。如果您手动进行,则涉及两个步骤。
第一步需要您在浏览器中对用户进行身份验证,然后才能调用任何API。
在此步骤中,您需要传递集成密钥并重定向回您的URL。
重定向回后,您将收到一个代码,可以使用您讨论的API调用将其交换为访问令牌。
I recommend you use a library for OAuth in .NET/C#. If you want to see how this is done, please clone this repo. The issue is that you need to first get a code and then exchange it for a token. There are 2 steps involved if you do this manually. The first step requires you to authenticate the user in a browser before you can call any API. During that step you need to pass in your integration key and redirect back to your URL. Once redirected back you'll receive a code that can be exchanged for an access token using the API call you had talks about.