DocuSign的requestJWTUserToken方法错误显示为“未初始化”

时间:2019-08-16 20:03:23

标签: node.js docusignapi

我正在尝试按照以下代码示例实施DocuSign JWT Auth:https://github.com/docusign/eg-01-node-jwt/blob/master/lib/dsJwtAuth.js

但是在调用requestJWTUserToken()时出现此错误:

Error: Not initialised
at Sign.update (crypto.js:99:16)
at Object.sign (/code/node_modules/jwa/index.js:159:23)
at Object.jwsSign [as sign] (/code/node_modules/jws/lib/sign-stream.js:32:24)
at Object.module.exports [as sign (/code/node_modules/jsonwebtoken/sign.js:190:16)
at generateAndSignJWTAssertion (/code/node_modules/docusign-esign/src/ApiClient.js:63:16)
at exports.requestJWTUserToken (/code/node_modules/docusign-esign/src/ApiClient.js:892:19)
at ConsentGateway.<anonymous> (/code/app/gateways/ConsentGateway.ts:73:53)
at Generator.next (<anonymous>)
at /code/app/gateways/ConsentGateway.ts:19:71
at new Promise (<anonymous>)
at __awaiter (/code/app/gateways/ConsentGateway.ts:15:12)
at ConsentGateway.getToken (/code/app/gateways/ConsentGateway.ts:64:16)
at ConsentGateway.<anonymous> (/code/app/gateways/ConsentGateway.ts:54:41)
at Generator.next (<anonymous>)
at /code/app/gateways/ConsentGateway.ts:19:71
at new Promise (<anonymous>)
at __awaiter (/code/app/gateways/ConsentGateway.ts:15:12)
at ConsentGateway.checkToken (/code/app/gateways/ConsentGateway.ts:46:16)
at ConsentGateway.<anonymous> (/code/app/gateways/ConsentGateway.ts:139:24)
at Generator.next (<anonymous>)
at /code/app/gateways/ConsentGateway.ts:19:71
at new Promise (<anonymous>)
at __awaiter (/code/app/gateways/ConsentGateway.ts:15:12)
at ConsentGateway.getTemplateList (/code/app/gateways/ConsentGateway.ts:132:16)
at ConsentService.<anonymous> (/code/app/services/ConsentService.ts:58:50)
at Generator.next (<anonymous>)
at /code/app/services/ConsentService.ts:19:71
at new Promise (<anonymous>)

调用该方法的代码如下:

private async getToken(reqId: string): Promise<any> {
        try {
            const pathToPrivateKey = fs.readFileSync(path.resolve('/code/app/gateways/', 'test.pem'));
            this.dsApiClient.setOAuthBasePath(this.authServer);
            const jwtToken = await this.dsApiClient.requestJWTUserToken(
                this.integrationKey, // clientId
                this.guidAccountId, // userId
                'signature',
                pathToPrivateKey,
                10 * 60
            );
            const expiresAt = moment().add(jwtToken.body.expires_in, 's');
            return { accessToken: jwtToken.body.access_token, tokenExpirationTimestamp: expiresAt };
        } catch (e) {
            this.logger.error(
                'Consent Error', reqId, ['accessToken'], { status: e.response.body.errorCode, message: e.response.body.message }
            );
        }
    }

我找不到关于requestJWTUserToken方法的任何文档,这使此错误难以调试。 是否有人熟悉节点中的JWT Auth流可以帮助解决这个问题?

1 个答案:

答案 0 :(得分:0)

这是您必须确保的事情:

  • 您具有正确配置的集成密钥(clientID)。
  • 您具有RSA私钥。该密钥已被复制/粘贴到与您的配置文件完全相同的位置。必须保留新行
  • 您的URL与环境匹配。这意味着您将account-d和demo.docusign.net用于沙箱环境端点。
  • 您需要userId,这是将被模拟的用户的GUid。该用户必须同意该应用程序。您必须确保您传递的是userId而不是accountId,并且它与您要使用的帐户相同。

如果您确认所有这些操作仍然出现错误-我会考虑使用我们的代码示例开始。我没有在您的问题中看到代码,但是我们的代码示例应该是一个很好的开始。