参考文献:https://developers.docusign.com/platform/auth/authcode/authcode-get-token/
我对步骤2有一个问题:获取访问令牌
我想要一个访问令牌。但是,我得到了以下错误:
{
"error": "invalid_grant",
"error_description": "unsupported_grant_type"
}无论是使用c#代码还是使用PostMan,我都会得到上面的错误。
在PostMan网址中:https://account-d.docusign.com/oauth/token方法: Post
标头
Authorization: BASIC BASE64_COMBINATION_OF_INTEGRATION_AND_SECRET_KEYS
Content_Type: application/json;charset=utf-8身体:我试过表格数据,x.www.form-urlencode,原始的.一切都是一样的
grant_type: authorization_code
code: My_AUTHORIZATION_CODE在获得授权代码时,我还尝试在回调页中获取访问令牌。
protected void Page_Load(object sender, EventArgs e)
{
var url = ConfigurationManager.AppSettings["DocuSign.TokenEndPoint"];
var data = $"grant_type=authorization_code=&{Request.QueryString["Code"]}";
WebRequest req = WebRequest.Create(url);
req.Method = "POST";
req.ContentLength = data.Length;
req.ContentType = "application/json; charset=UTF-8";
UTF8Encoding enc = new UTF8Encoding();
var code64 = Convert.ToBase64String(enc.GetBytes($"{ConfigurationManager.AppSettings["DocuSign.ClientId"]}:{ConfigurationManager.AppSettings["DocuSign.ClientSecret"]}"));
req.Headers.Add("Authorization", "Basic " + code64);
using (Stream ds = req.GetRequestStream())
{
ds.Write(enc.GetBytes(data), 0, data.Length);
}
WebResponse wr = req.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
Response.Write(content);
}发布于 2021-04-29 15:01:33
以下一行是错误的:
var data = $"grant_type=authorization_code=&{Request.QueryString["Code"]}";变到
var data = $"grant_type=authorization_code&code={Request.QueryString["Code"]}";我想念code=
发布于 2021-04-19 16:39:40
您的content_type应该是application/x-www-form-urlencoded。
https://stackoverflow.com/questions/67129980
复制相似问题