auth0 / node-jsonwebtoken

JsonWebToken implementation for node.js http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html
MIT License
17.74k stars 1.23k forks source link

Cyrillic characters #938

Open omqmo opened 1 year ago

omqmo commented 1 year ago

How to fix this example?

import jwt from "jsonwebtoken";

// let o = { name: `Hello World!`}
let o = { name: `Привет Мир!`}
let token = jwt.sign( o, `secret`, {
  expiresIn: `1h`,
} );

let [, payload] = token.split( `.` );
let text = atob( payload ); // Error

In terminal npm start stackblitz

miswanting commented 1 year ago

Same here.

Some Chinese characters face the same problem.

import jwt from 'jsonwebtoken';

// let o = { name: `大` }; // OK case
let o = { name: `使` }; // Error case

let token = jwt.sign(o, `secret`, {
  expiresIn: `1h`,
});

let [, payload] = token.split(`.`);
console.log(payload);
let text = atob(payload); // throw Error
console.log(text);

stackblitz

akalter commented 6 months ago

The issue is not related to this library. If you will do btoa("使") you will have the same problem, the problem is the btoa/atob functions.

If you use jwt.verify or jwt.decode to extract the data from the jwt you will see that it is working as expected.