auth0 / node-jsonwebtoken

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

Cyrillic characters #938

Open omqmo opened 11 months ago

omqmo commented 11 months 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 11 months 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 3 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.