首页 > 解决方案 > 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);

    }

标签: docusignapi

解决方案


你的 content_type 应该是 application/x-www-form-urlencoded


推荐阅读