Decoded jwt code example
Example 1: javascript token generator
function generate_token(length){
var a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".split("");
var b = [];
for (var i=0; i<length; i++) {
var j = (Math.random() * (a.length-1)).toFixed(0);
b[i] = a[j];
}
return b.join("");
}
generate_token(32);
Example 2: js jwt decode
import jwt_decode from "jwt-decode";
var token = "eyJ0eXAiO...";
var decoded = jwt_decode(token);
console.log(decoded);
Example 3: jsonwebtoken
RSASHA256(
base64UrlEncode(header) + "." +
base64UrlEncode(payload),
,
)
Example 4: local jwt decode
import jwt_decode from "jwt-decode";
var token = "eyJ0eXAiO.../// jwt token";
var decoded = jwt_decode(token);
console.log(decoded);
var decodedHeader = jwt_decode(token, { header: true });
console.log(decodedHeader);