简体   繁体   English

DocuSign API身份验证问题

[英]DocuSign API Authentication Problems

I'm just trying to play with the Docusign API for NodeJS in order to get document signing integration for an app I'm building. 我只是尝试使用Docusign API for NodeJS来为正在构建的应用程序获取文档签名集成。 I think I have the basic auth handshake working. 我认为我已经完成了基本的身份验证握手。 I created test routes at /docusign and /docusign/auth and I'm able to get an access token with the following code. 我在/docusign/docusign/auth创建了测试路由,并且可以使用以下代码获取访问令牌。

I just want to get a test signing link in my email from a doc I already uploaded as a tempalte, but the createEnvelope call ends in the up in catch with the error: 我只想从已经以临时文件上传的文档中获取电子邮件中的测试签名链接,但是createEnvelope调用最终会出现错误:

USER_AUTHENTICATION_FAILED One or both of Username and Password are invalid. Invalid access token

provide.generateAccessToken = (req, res, next) => {
apiClient.generateAccessToken(integratorKey, clientSecret, req.query.code, function (err, oAuthToken) {

    console.log(oAuthToken);
    apiClient.setBasePath(basePath);
    //IMPORTANT: In order to access the other api families, you will need to add this auth header to your apiClient.
    apiClient.addDefaultHeader('Authorization', 'Bearer ' + oAuthToken.accessToken);
    var envelopesApi = new docusign.EnvelopesApi();
    envelopesApi.apiClient.addDefaultHeader('Authorization', 'Bearer ' + oAuthToken.accessToken);
    apiClient.getUserInfo(oAuthToken.accessToken, function (err, userInfo) {
        console.log("UserInfo: " + userInfo);
        // parse first account's baseUrl
        // below code required for production, no effect in demo (same
        // domain)
        //apiClient.setBasePath(userInfo.accounts[0].baseUri + "/restapi");
       // create a new envelope object that we will manage the signature request through
        var envDef = new docusign.EnvelopeDefinition();
        envDef.emailSubject = 'Rental Application';
        envDef.templateId = '66c8c9cf-xxx-xxxx-xxxx-xxxxxxxx';

        // create a template role with a valid templateId and roleName and assign signer info
        var tRole = new docusign.TemplateRole();
        tRole.roleName = 'Applicant';
        tRole.name = 'test';
        tRole.email = 'myemailtest@gmail.com';

        // create a list of template roles and add our newly created role
        var templateRolesList = [];
        templateRolesList.push(tRole);

        // assign template role(s) to the envelope
        envDef.templateRoles = templateRolesList;

        // send the envelope by setting |status| to 'sent'. To save as a draft set to 'created'
        envDef.status = 'sent';

        // use the |accountId| we retrieved through the Login API to create the Envelope
        var accountId = userInfo.sub;

        // instantiate a new EnvelopesApi object

        // call the createEnvelope() API
        envelopesApi.createEnvelope(accountId, {'envelopeDefinition': envDef}, function (err, envelopeSummary, response) {
        if (err) {
            return next(err);
        }
        console.log('EnvelopeSummary: ' + JSON.stringify(envelopeSummary));
        return JSON.stringify(envelopeSummary);
        });
    });
});

} }

Any help to point me in the right direction would be greatly appreciated! 任何帮助我指出正确方向的帮助将不胜感激!

Thanks! 谢谢!

Instead of 代替

    var envelopesApi = new docusign.EnvelopesApi();

try 尝试

    var envelopesApi = new docusign.EnvelopesApi(apiClient);

Also, for a working example of Node with DocuSign and Authorization Code Grant, check out this example. 另外,有关带有DocuSign和授权代码授予的Node的工作示例,请查看此示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM