Skip to main content
Question

Help with error: 'invalid_grant', error_description: 'no_valid_keys_or_signatures'

  • March 31, 2024
  • 0 replies
  • 317 views

Forum|alt.badge.img+1

My integration was working fine, but now I'm getting the following error:

  • error: 'invalid_grant'
  • error_description: 'no_valid_keys_or_signatures'

Has the Docusign integration undergone any updates that I need to fix in my application?

Everything was working fine, and the documentation doesn't have clear information about the error.

This is the function and the error response when accessing results from:

const result = await axios.post(https://account-d.docusign.com/oauth/token, {   grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",   assertion: token });

 

**The token was generated correctly with no errors using the following code and using the private key generated in the application.**

It seems that everything is okay with the token. It has an exp field and other fields are valid.

{
  "iss": "e928cdc2-424f-4f40-a5f0-a9de31184d91",
  "sub": "d19b282f-a65c-4302-b08e-3ea5cd7e3167",
  "aud": "account-d.docusign.com",
  "iat": 1711921494,
  "exp": 2532368131,
  "scope": "signature"
}
Code:
try {
        let privateKEY = fs.readFileSync(path.join(__dirname, "../../utils/static/private.key"), "utf8");
        const dateNow = new Date().getTime();
        const sevenDaysLater = dateNow + 7 * 24 * 60 * 60 * 1000;

        let payload = {
            iss: appConstant.integrationKey,
            sub: user.docusign.sub,
            aud: appConstant.baseUri,
            iat: Math.floor(Date.now() / 1000),
            exp: 2532368131,
            scope: "signature"
        };
        console.log("🚀 ~ generateDocusignToken ~ payload:", payload)

        let signOptions = {
            algorithm: "RS256"
        } as jwt.SignOptions;

        let token = jwt.sign(payload, privateKEY, signOptions);

        const result = await axios.post(`https://${appConstant.baseUri}/oauth/token`, {
            grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
            assertion: token
        });
        return result.data;
    } catch (error) {
        console.log("ERRO AO GERAR TOKEN DA DOCUSIGN", error);
    }


Erro:
ERRO AO GERAR TOKEN DA DOCUSIGN [AxiosError: Request failed with status code 400] {
  code: 'ERR_BAD_REQUEST',
  config: {
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    adapter: [Function: httpAdapter],
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    env: { FormData: [Function] },
    validateStatus: [Function: validateStatus],
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      'User-Agent': 'axios/0.27.2',
      'Content-Length': 690
    },
    method: 'post',
    url: 'https://account-d.docusign.com/oauth/token',
    data: '{"grant_type":"urn:ietf:params:oauth:grant-type:jwt-bearer","assertion":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlOTI4Y2RjMi00MjRmLTRmNDAtYTVmMC1hOWRlMzExODRkOTEiLCJzdWIiOiJkMTliMjgyZi1hNjVjLTQzMDItYjA4ZS0zZWE1Y2Q3ZTMxNjciLCJhdWQiOiJhY2NvdW50LWQuZG9jdXNpZ24uY29tIiwiaWF0IjoxNzExOTIwODc2LCJleHAiOjI1MzIzNjgxMzEsInNjb3BlIjoic2lnbmF0dXJlIn0.AoT4t0YPhvlVmm8Yo157imELrO1o9EsPgyTJhHwGlXd2JggPyDgSpyL_f8tN9ndyJVAtiggFLwmBn50rxYfzwF1R808PD0gMERtP8_6aQgHa9zWUapDsq-c2N4QobpyBpbEx7_4tQGWAtSVWtjsM9yIruyl6VrrP7vRXuhQy3z6lOrYEprItmeDg_oqMuBqRB-_WrxoJRA7Q5BiHu43PS7Azhs_7oOvPb9RIr2uEbwjVrH5oAZk3elX6wdwPrR8SiGzUPgiwNem-JjEtzFscQxV0pnqOJ8kYjz1OhOj6DQq9GrqECfdl6S4QfCilI_0W_lF0NoG5YxU3P3UMpYIjmQ"}'
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      finish: [Function: requestOnFinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: true,
    _last: false,
    chunkedEncoding: false,
    shouldKeepAlive: true,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: true,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    strictContentLength: false,
    _contentLength: 690,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: true,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: 'account-d.docusign.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 9,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'account-d.docusign.com',
      _closeAfterHandlingError: false,
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      timeout: 5000,
      parser: null,
      _httpMessage: null,
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: -1,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: Timeout {
        _idleTimeout: 5000,
        _idlePrev: [TimersList],
        _idleNext: [Timeout],
        _idleStart: 801422,
        _onTimeout: [Function: bound ],
        _timerArgs: undefined,
        _repeat: null,
        _destroyed: false,
        [Symbol(refed)]: false,
        [Symbol(kHasPrimitive)]: false,
        [Symbol(asyncId)]: 16902,
        [Symbol(triggerId)]: 16900
      },
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(kSetKeepAlive)]: true,
      [Symbol(kSetKeepAliveInitialDelay)]: 1,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object]
    },
    _header: 'POST /oauth/token HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'Content-Type: application/json\r\n' +
      'User-Agent: axios/0.27.2\r\n' +
      'Content-Length: 690\r\n' +
      'Host: account-d.docusign.com\r\n' +
      'Connection: keep-alive\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: nop],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype] {},
      freeSockets: [Object: null prototype],
      keepAliveMsecs: 1000,
      keepAlive: true,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 1,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'POST',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    joinDuplicateHeaders: undefined,
    path: '/oauth/token',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      socket: null,
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      joinDuplicateHeaders: undefined,
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 400,
      statusMessage: 'Bad Request',
      client: [TLSSocket],
      _consuming: false,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'https://account-d.docusign.com/oauth/token',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 28,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'account-d.docusign.com',
    protocol: 'https:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 690,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'https://account-d.docusign.com/oauth/token',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kBytesWritten)]: 0,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'content-type': [Array],
      'user-agent': [Array],
      'content-length': [Array],
      host: [Array]
    },
    [Symbol(errored)]: null,
    [Symbol(kHighWaterMark)]: 16384,
    [Symbol(kRejectNonStandardBodyWrites)]: false,
    [Symbol(kUniqueHeaders)]: null
  },
  response: {
    status: 400,
    statusText: 'Bad Request',
    headers: {
      'cache-control': 'no-cache, no-store, must-revalidate',
      pragma: 'no-cache',
      'content-type': 'application/json; charset=utf-8',
      expires: '-1',
      'x-docusign-tracetoken': '6acc3310-5a37-4399-9e20-557989223729',
      'x-frame-options': 'SAMEORIGIN',
      'x-xss-protection': '1; mode=block; report=/client-errors/xss',
      'x-docusign-node': 'DA1DFE5',
      'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
      'referrer-policy': 'no-referrer,strict-origin-when-cross-origin',
      'x-content-type-options': 'nosniff',
      date: 'Sun, 31 Mar 2024 21:34:36 GMT',
      'content-length': '75',
      vary: 'Accept-Encoding'
    },
    config: {
      transitional: [Object],
      adapter: [Function: httpAdapter],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      env: [Object],
      validateStatus: [Function: validateStatus],
      headers: [Object],
      method: 'post',
      url: 'https://account-d.docusign.com/oauth/token',
      data: '{"grant_type":"urn:ietf:params:oauth:grant-type:jwt-bearer","assertion":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlOTI4Y2RjMi00MjRmLTRmNDAtYTVmMC1hOWRlMzExODRkOTEiLCJzdWIiOiJkMTliMjgyZi1hNjVjLTQzMDItYjA4ZS0zZWE1Y2Q3ZTMxNjciLCJhdWQiOiJhY2NvdW50LWQuZG9jdXNpZ24uY29tIiwiaWF0IjoxNzExOTIwODc2LCJleHAiOjI1MzIzNjgxMzEsInNjb3BlIjoic2lnbmF0dXJlIn0.AoT4t0YPhvlVmm8Yo157imELrO1o9EsPgyTJhHwGlXd2JggPyDgSpyL_f8tN9ndyJVAtiggFLwmBn50rxYfzwF1R808PD0gMERtP8_6aQgHa9zWUapDsq-c2N4QobpyBpbEx7_4tQGWAtSVWtjsM9yIruyl6VrrP7vRXuhQy3z6lOrYEprItmeDg_oqMuBqRB-_WrxoJRA7Q5BiHu43PS7Azhs_7oOvPb9RIr2uEbwjVrH5oAZk3elX6wdwPrR8SiGzUPgiwNem-JjEtzFscQxV0pnqOJ8kYjz1OhOj6DQq9GrqECfdl6S4QfCilI_0W_lF0NoG5YxU3P3UMpYIjmQ"}'
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: true,
      _last: false,
      chunkedEncoding: false,
      shouldKeepAlive: true,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 690,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: true,
      socket: [TLSSocket],
      _header: 'POST /oauth/token HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'User-Agent: axios/0.27.2\r\n' +
        'Content-Length: 690\r\n' +
        'Host: account-d.docusign.com\r\n' +
        'Connection: keep-alive\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '/oauth/token',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'account-d.docusign.com',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kHighWaterMark)]: 16384,
      [Symbol(kRejectNonStandardBodyWrites)]: false,
      [Symbol(kUniqueHeaders)]: null
    },
    data: {
      error: 'invalid_grant',
      error_description: 'no_valid_keys_or_signatures'
    }
  }
}

0 replies

Be the first to reply!