Skip to content

Instantly share code, notes, and snippets.

@lechidung lechidung/js
Last active Dec 7, 2018

Embed
What would you like to do?
jwt - source code generate jwt
var header = {
"alg": "RS256",
"typ": "JWT"
};
var stringifiedHeader = CryptoJS.enc.Utf8.parse(JSON.stringify(header));
var encodedHeader = base64url(stringifiedHeader);
var data = {
"username": "ledung",
"userid": "1132454",
"role": "planers",
"service": "games",
"premium": 1
};
var stringifiedData = CryptoJS.enc.Utf8.parse(JSON.stringify(data));
var encodedData = base64url(stringifiedData);
var token = encodedHeader + "." + encodedData;
var secret = "Primary key cert";
var signature = CryptoJS.HmacSHA256(token, secret);
signature = base64url(signature);
var signedToken = token + "." + signature;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.