首页 > 解决方案 > 为 DocuSign 创建 JWT

问题描述

伙计们,你们好吗?

我想知道是否有人可以帮助我解决这个问题......

我正在尝试使用 JWT 将我的 API 与 DocuSign 集成。我从 DocuSign API 收到以下错误:

data: {
      error: 'invalid_grant',
      error_description: 'no_valid_keys_or_signatures'
    }

根据 JWT 正确时发生的文档,但有些声明不正确。

这是文档链接:https ://developers.docusign.com/platform/auth/jwt/jwt-get-token

我有点担心,因为我所做的声明与文档要求的完全一样。

连接授权已经完成。

这是我创建 JWT 的数据:

 const data = {
    iss: req.body.iss,
    sub: req.body.sub,
    name: req.body.name,
    iat: timeStamp,
    exp: timeStamp + 60 * 60 * 1000,
    aud: req.body.aud,
    scope: req.body.scope,
  };

请求是:

{
    "iss": "INTEGRATION_KEY",
    "sub": "ACCOUNT_ID",
    "name": "Ruben Acevedo",
    "aud": "account-d.docusign.com",
    "scope": "signature impersonation"
}

(密钥的值因隐私而改变)

我正在创建这样的令牌:

const createToken = (data) => {
  const privateKey = fs.readFileSync(key);

  const token = jwt.sign(data, privateKey, {
    algorithm: "RS256",
  });

  return token;
};

并且对docusign api的发布请求是这样的:

axios({
    method: "post",
    url: "https://account-d.docusign.com/oauth/token",
    data: `grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=${token}`,
  })
    .then((response) => console.log(response))
    .catch((e) => console.log(e));
});

你们能帮助新手完成他的项目吗?哈哈

谢谢大家!!

标签: node.jsjwtdocusignapi

解决方案


Ruben, we're doing great, thanks for asking. I suggest you try to spend 2-3 min generating the DocuSign quickstart for Node.js and see if the JWT option there works for you (you would have to first run it with Auth Code Grant or change the quickstart="true" in the configuration file to use JWT).

This would give you a working version that is using the Node SDK. It's going to also set everything up for you (RSA Key, IK, etc) which could also be your issue.

If that works - you can either use it, or you can try to see what you did wrong in your code.


推荐阅读