docusignapi - Docusign:获取访问令牌
问题描述
参考: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 方法:发布
标头
Authorization: BASIC BASE64_COMBINATION_OF_INTEGRATION_AND_SECRET_KEYS
Content_Type: application/json;charset=utf-8
正文:我试过form-data、x.www.form-urlencoded、raw……都一样
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);
}
解决方案
你的 content_type 应该是 application/x-www-form-urlencoded
推荐阅读
- php - PHP日期格式(我想将日期(Ymd)转换为(Y,m,d)格式
- symfony - Symfony 4 - 更改公用文件夹路径(未指定输入文件。错误)
- mongodb - 不同版本和环境中的mongodb查询速度慢
- matplotlib - 关于在 anaconda 环境中使用 pip 的安装错误信息
- android - 无法在已部署的反应本机应用程序上使用 IP 地址进行本地网络调用
- spring - 在聊天应用程序上建立相同服务的 Pod 间通信
- sharepoint-online - 使用 pnp.js 作为 CDN 在线项目
- excel - 仅复制 WorkSheet VBA 代码而不是数据
- python - str 的 .index 方法如何在 python 中工作?
- sql - 使用 SQL 查询从表中提取数据