Generate RS256 JWT

Good afternoon community, how are you doing?

Here I come with a new query, I wanted to know if it could be generated through n8n token with JWT Grant RS256 I read this Docu: link DocuSign but I am not finding the return to be able to generate it. If you have any info or something that can help, thank you very much!


And when I put it in this URL the JWT tells me that it is incorrect in Base64

This would be what you should put together in the code node

Thank you very much as always for your willingness to help!

Information on your n8n setup

  • **n8n version:1.27.2
  • **Database (default: SQLite):postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):Kubernetes
  • Operating system:

hello @Internalit_Automatio

Well, It didn’t work for me with RSA256, but it works with HMAC256

Example below:


Hi @barn4k

I was able to solve it with RS256, I’ll pass you the code!.

const crypto = require('crypto');

// Definimos Header y Body
const header = {
  alg: 'RS256',
  typ: 'JWT'

const body = {
  iss: 'XXXX-XXX',
  sub: 'XXXX-XXXX',
  aud: '',
  iat: Math.floor( / 1000), // Tiempo actual en formato UNIX epoch
  exp: Math.floor( / 1000) + 6000, // Tiempo actual + 6000 segundos
  scope: 'signature impersonation'

// Codificamos el Header y Body
const base64UrlEncode = (data) => {
  return Buffer.from(JSON.stringify(data)).toString('base64')
    .replace(/=/g, '')
    .replace(/\+/g, '-')
    .replace(/\//g, '_');

const encodedHeader = base64UrlEncode(header);
const encodedBody = base64UrlEncode(body);

// Combinamos el Header + Body
const payload = `${encodedHeader}.${encodedBody}`;

// Colocamos la llave Pública y Privada
const privateKey = `-----BEGIN RSA PRIVATE KEY-----


const publicKey = `-----BEGIN PUBLIC KEY-----

-----END PUBLIC KEY-----`;

// Firmamos el payload con la clave privada
const signer = crypto.createSign('RSA-SHA256');
const signature = signer.sign(privateKey, 'base64');

// Codificar la firma utilizando base64url
const encodedSignature = signature.toString('base64')
    .replace(/=/g, '')
    .replace(/\+/g, '-')
    .replace(/\//g, '_');

//Resultado Final
const jwtToken = `${payload}.${encodedSignature}`;

return [
    key: 'JWT generado',
    value: jwtToken


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.