【问题标题】:DocuSign JWT Grant flow gives an "invalid_grant" errorDocuSign JWT 授权流程给出“invalid_grant”错误
【发布时间】:2019-03-25 01:52:57
【问题描述】:

有没有人遇到过此处主题中提到的 invalid_grant 错误,导致调用 ApiClient.RequestJWTUserToken 时出错?

这是我的电话。我已验证我的 DSConfig 字段有值。

private void UpdateToken()
    {
        ApiClient docusign_api = new ApiClient();
        DSConfig cfg = new DSConfig();
        const int jwtLifeSec = 10 * 60; // requested lifetime 
//for the JWT     is     10 min
        List<string> scopes = new List<string>();
            scopes.Add("signature");
 // impersonation scope is implied due to use of JWT grant

    OAuth.OAuthToken authToken = docusign_api.RequestJWTUserToken    (DSConfig.ClientID,
                    DSConfig.ImpersonatedUserGuid,
                    DSConfig.AuthServer,
                    Encoding.UTF8.GetBytes(DSConfig.PrivateKey),
                    jwtLifeSec, scopes);

        AccessToken = authToken.access_token;

        if (Account == null)
            Account = GetAccountInfo(authToken);

        docusign_api = new ApiClient(Account.BaseUri + "/restapi");

        expiresIn = DateTime.Now.Second + authToken.expires_in.Value;
    }

public OAuth.OAuthToken RequestJWTUserToken(string clientId, string userId, string oauthBasePath, byte[] privateKeyBytes, int expiresInHours, List<string> scopes = null);

【问题讨论】:

  • 您在 DSConfig.AuthServer 参数中传递了什么值?
  • 我使用account-d.docusign.com作为AuthServer
  • 通常情况下,当调用中的任何输入参数无效时,我们会得到 invalid_grant,您可以尝试使用JWT 之类的网站在代码外部创建令牌,负载看起来像{ "iss": "IntegratorKey", "sub": "UserId", "iat": 1536700971, "exp": 1536704571, "aud": "account-d.docusign.com", "scope": "impersonation signature" }
  • 然后使用 PostMan 执行 POST 调用 https://account-d.docusign.com/oauth/token 请求正文为 grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&amp;assertion=jwtassertioncreatedfromjwt.iowebsiteContent-Type 将是 application/x-www-form-urlencoded
  • 我更改了我的 AuthServer 参数并且不再获得 invalid_grant。我现在得到'consent_required'。我应该为 impersonatedUserGUID 使用 API 帐户用户吗?

标签: docusignapi


【解决方案1】:

看起来您没有使用正确的参数。

第三个参数是scopes 参数,而不是服务器。

对于 Node.js,试试这个:

const jwtLifeSec = 10 * 60, // requested lifetime for the JWT is 10 min
      scopes = "signature", // impersonation scope is implied due to use of JWT grant
      dsApi = new docusign.ApiClient();

dsApi.setOAuthBasePath(dsConfig.authServer);
const results = await dsApi.requestJWTUserToken(dsConfig.clientId,
      dsConfig.impersonatedUserGuid, scopes, dsConfig.privateKey,
      jwtLifeSec);

【讨论】:

  • 这是我拥有的版本的方法签名: // JWT 用户令牌 public OAuth.OAuthToken RequestJWTUserToken(string clientId, string userId, string oauthBasePath, Stream privateKeyStream, int expiresInHours, List scopes = null);
  • 哦,你用的是Java吗?我的例子是节点。请编辑您的问题以包含您的代码。评论中的代码并没有真正的帮助。谢谢。
  • 我正在使用 C# .Net 框架。我有一个网络表单应用程序,我正在尝试将嵌入式登录集成到其中。我唯一还没有工作的是 JWT Auth。更新初始问题中的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-17
  • 2019-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-25
  • 1970-01-01
相关资源
最近更新 更多