Decoding a JWT token in NodeJS
JWT (or JSON Web Tokens) are an open, industry standard RFC 7519 method for representing claims securely between two parties.
It carries a lot of information in the encoded form in a HTTP/HTTPS request after a successful authentication. For instance, when we talk about multi-tenant cloud, a JWT can contain a domain/tenant information, JWT expiration details and/or subject in its body part. But wait? What does a body part looks like in a JWT Payload structure.
JWT payload structure:-
Here, if you look at carefully, JWT has three parts in it separated by a dot (.), whereas first part (in red) specifies header information, followed by body part (in pink) and then followed by signature (in blue).
Good thing about JWT is that it encodes the entire payload itself before it is transmitted over the network.
Let’s look at how you can decode it in NodeJS using Buffer library:-
const decodingJWT = (token) => {
console.log(‘decoding JWT token’);
if(token !== null || token !== undefined){
const base64String = token.split(‘.’)[1];
const decodedValue =…