DocuSign" invalid_grant"在发布jwtToken

时间:2018-01-31 20:45:52

标签: oauth jwt docusignapi

我试图实现"服务集成身份验证"按照此处的步骤docusign docs进行操作,直到请求访问令牌,然后发送jwt令牌(格式正确)

我总是得到" invalid_grant" ,根据该文档,是因为某些声明无效。这个错误还有其他原因吗? 所有声明看起来都不错

C#:

//request access token
        var client3 = new RestClient("https://" + _host);
        var request3 = new RestRequest("/oauth/token", Method.POST);
        request3.AddHeader("Content-Type", "application/x-www-form-urlencoded");
        request3.AddParameter("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer");

        var headers = new[]
        {
            new Claim("alg", "RS256"),
            new Claim("typ", "JWT"),
        }.ToList();

        var claims = new[] {
            new Claim("iss", _integrationKey), //<-- integration key
            new Claim("sub", OAuthGrant.Sub), //<-- returned from /oauth/userinfo (OK)
            new Claim("iat", ToUnixTime(DateTime.Now).ToString(), ClaimValueTypes.Integer64),
            new Claim("exp", ToUnixTime(DateTime.Now.AddHours(1)).ToString(), ClaimValueTypes.Integer64),
            new Claim("aud", _host), //<-- "account-d.docusign.com"
            new Claim("scope", "signature"),
        }.ToList();

        //build jwt from private key. token decodes just fine from https://jwt.io/
        var jwtToken = CreateToken(claims, headers, "private-key.pem", Server.MapPath("/"));
        request3.AddParameter("assertion", jwtToken);

        System.Diagnostics.Debug.WriteLine("jwtToken:" + jwtToken);

        var response = client3.Execute<OAuthToken>(request3);

        System.Diagnostics.Debug.WriteLine("response content:" + response.Content); //<-- getting "invalid_grant"

        return response.Data;

使用https://jwt.io/验证了jwt令牌并解码得很好。 是 docusign演示沙箱

提前致谢 丹尼尔

1 个答案:

答案 0 :(得分:0)

我的假设是您正在使用的库正在为您生成错误的断言。您也可以在DS SDK中查看DS SDK - ConfigureJwtAuthorizationFlow方法,它将帮助您按照DS API的预期正确生成断言。