简体   繁体   中英

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. 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.

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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