Docusign:获取访问令牌

Docusign: Obtain the access token

参考:https://developers.docusign.com/platform/auth/authcode/authcode-get-token/

我在第 2 步:获取访问令牌

时遇到问题

我正在尝试获取访问令牌。但是我收到以下错误:

{
    "error": "invalid_grant",
    "error_description": "unsupported_grant_type"
}

无论是使用 c# 代码还是使用 PostMan 我都收到了上面的错误。

在Post男人 URL: https://account-d.docusign.com/oauth/token 方法:Post

Headers

Authorization:  BASIC BASE64_COMBINATION_OF_INTEGRATION_AND_SECRET_KEYS

Content_Type: application/json;charset=utf-8

Body: 我试过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

下面一行是错误的:

 var data = $"grant_type=authorization_code=&{Request.QueryString["Code"]}";

改为

 var data = $"grant_type=authorization_code&code={Request.QueryString["Code"]}";

我漏了代码=