docusign-esign-node-client: Generate Access Token SDK Method is broken since most recent RC Version

When trying to generate token with generateAccessToken using the client it just don’t work, throws an empty error (see screenshot). With previous version it works as usual, anything changed for that?

image

Update: Just found the issue in your code, please merge this PR ASAP

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

@sonawane-sanket will create a POC today.

It looks like the issue is resolved in 7.0.3 for me. Thanks!

@nikodunk I found the issue niko,

If you use addDefaultHeader

const apiClient = new ApiClient();
apiClient.addDefaultHeader('Authorization', `Bearer ${tokensParsed.accessToken}`);

You are writing defaultHeaders in a global scope inside the library

  /**
   * Adds request headers to the API client. Useful for Authentication.
   */
  exports.prototype.addDefaultHeader = function addDefaultHeader(
    header,
    value
  ) {
    defaultHeaders[header] = value;
  };

So every time need to create a new client instace You must call addDefaultHeader

const apiClient = new ApiClient();
apiClient.setOAuthBasePath(this.docuSignKeys.oAuthApi);
apiClient.addDefaultHeader(
  'Authorization',
  `Basic ${Buffer.from(clientComb).toString('base64')}`
);

Because the way that you override headers in generateAccessToken image

SOLUTION: So you MUST internally RESET global default headers every time a new api client instance is created to avoid this issue.

@Ivanrenes I reviewed your comment. We’ll validate it internally and get back to you at the earliest. Thank you for bringing this to our attention.