Skip to content

Instantly share code, notes, and snippets.

@monkey-codes
Created November 29, 2016 05:08
Show Gist options
  • Select an option

  • Save monkey-codes/a716920201c8569de5539f65dc1d54a6 to your computer and use it in GitHub Desktop.

Select an option

Save monkey-codes/a716920201c8569de5539f65dc1d54a6 to your computer and use it in GitHub Desktop.
JWT breakdown pseudo code
var header = {
"alg": "RS256",
"typ": "JWT"
};
var payload = {
"exp": 1480395277, //Reserved claim - Expiration time
"user_name": "reader", //Public claim
"authorities": [ //Public claim
"ROLE_READER"
],
"jti": "5acda3f8-4c85-4000-a01f-b92a3738197a", //Reserved claim - JWT ID
"client_id": "web-app", // Public claim
"scope": [ // Public claim
"read"
]
};
var encodedString = base64UrlEncode(header) + "." + base64UrlEncode(payload);
var privateKey = 'secret private key...';
var signature = SHA256withRSA(encodedString, privateKey);
var JWT = encodedString + "." + base64UrlEncode(signature);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment