【问题标题】:Docusign: Obtain the access tokenDocusign:获取访问令牌
【发布时间】:2021-04-16 17:50:05
【问题描述】:

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

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

时遇到问题

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

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

无论是使用 c# 代码还是使用 PostMan,我都会收到上述错误。

在邮递员中 网址:https://account-d.docusign.com/oauth/token 方法:发布

标题

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);

    }

【问题讨论】:

标签: docusignapi


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    以下行是错误的:

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

    改为

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

    我缺少代码=

    【讨论】:

      猜你喜欢
      • 2021-02-12
      • 2020-11-01
      • 2021-10-24
      • 1970-01-01
      • 2022-08-16
      • 2014-07-09
      相关资源
      最近更新 更多