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 OAxiosError: Request failed with status code 400] {
code: 'ERR_BAD_REQUEST',
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: dFunction: httpAdapter],
transformRequest: e uFunction: transformRequest] ],
transformResponse: s oFunction: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: rFunction] },
validateStatus: SFunction: 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: eObject: null prototype] {
abort: Function (anonymous)],
aborted: bFunction (anonymous)],
connect: oFunction (anonymous)],
error: Function (anonymous)],
socket: sFunction (anonymous)],
timeout: iFunction (anonymous)],
finish: fFunction: requestOnFinish]
},
_eventsCount: 7,
_maxListeners: undefined,
outputData: u],
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: pObject],
_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: eObject: null prototype],
_eventsCount: 9,
connecting: false,
_hadError: false,
_parent: null,
_host: 'account-d.docusign.com',
_closeAfterHandlingError: false,
_readableState: eReadableState],
_maxListeners: undefined,
_writableState: eWritableState],
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)]: nTLSWrap],
/Symbol(lastWriteQueueSize)]: 0,
/Symbol(timeout)]: Timeout {
_idleTimeout: 5000,
_idlePrev: lTimersList],
_idleNext: lTimeout],
_idleStart: 801422,
_onTimeout: iFunction: 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)]: iObject]
},
_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: nFunction: nop],
agent: Agent {
_events: eObject: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: pObject: null prototype],
requests: qObject: null prototype] {},
sockets: oObject: null prototype] {},
freeSockets: oObject: null prototype],
keepAliveMsecs: 1000,
keepAlive: true,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 1,
maxCachedSessions: 100,
_sessionCache: nObject],
/Symbol(kCapture)]: false
},
socketPath: undefined,
method: 'POST',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
joinDuplicateHeaders: undefined,
path: '/oauth/token',
_ended: true,
res: IncomingMessage {
_readableState: eReadableState],
_events: eObject: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
socket: null,
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
rawHeaders: eArray],
rawTrailers: a],
joinDuplicateHeaders: undefined,
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 400,
statusMessage: 'Bad Request',
client: cTLSSocket],
_consuming: false,
_dumped: false,
req: Circular *1],
responseUrl: 'https://account-d.docusign.com/oauth/token',
redirects: i],
/Symbol(kCapture)]: false,
/Symbol(kHeaders)]: dObject],
/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: eWritableState],
_events: eObject: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
_options: pObject],
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: i],
_requestBodyLength: 690,
_requestBodyBuffers: u],
_onNativeResponse: sFunction (anonymous)],
_currentRequest: eCircular *1],
_currentUrl: 'https://account-d.docusign.com/oauth/token',
/Symbol(kCapture)]: false
},
rSymbol(kCapture)]: false,
rSymbol(kBytesWritten)]: 0,
rSymbol(kNeedDrain)]: false,
rSymbol(corked)]: 0,
rSymbol(kOutHeaders)]: dObject: null prototype] {
accept: aArray],
'content-type': -Array],
'user-agent': aArray],
'content-length': eArray],
host: Array]
},
rSymbol(errored)]: null,
rSymbol(kHighWaterMark)]: 16384,
rSymbol(kRejectNonStandardBodyWrites)]: false,
rSymbol(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: tObject],
adapter: dFunction: httpAdapter],
transformRequest: eArray],
transformResponse: sArray],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: Object],
validateStatus: SFunction: validateStatus],
headers: eObject],
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: eObject: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: u],
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: sTLSSocket],
_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: nFunction: 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: cWritable],
/Symbol(kCapture)]: false,
/Symbol(kBytesWritten)]: 0,
/Symbol(kNeedDrain)]: false,
/Symbol(corked)]: 0,
/Symbol(kOutHeaders)]: dObject: 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'
}
}
}