pratiks
8/10/2017 - 2:10 PM

JWTs Explained

JWTs Explained


/* JSON Web Tokens consist of three parts separated by dots (.), which are:

Header
Payload
Signature

*/



// eyJhbGciOiJSUzI1NiIsImtpZCI6Im1pY3Jvcy9oYy1ib3QtbWFuYWdlci9wc2hhaC1hZXNvODlpdmJqMjJiaGczIiwidHlwIjoiSldUIn0.eyJhdWQiOiJpZGVudGl0eS1wbGF0Zm9ybSIsImV4cCI6MTUwMjMyMzA2MywiaWF0IjoxNTAyMzIzMDMzLCJpc3MiOiJtaWNyb3MvaGMtYm90LW1hbmFnZXIiLCJqdGkiOiI2OWIxNTMxMS1jMWExLTQ3MGEtYTY5Yi0xM2IzNDQxNDQ4OTUifQ.jFf5wgOSOWGP3X62iwkku-u3ss5uEgd1fbPjw_MMFOpvXqX8AS_vAir1AhWA1IYNPBm_azo2syYBeIEK7xu-92hcFDGeM_nhAz27p6L693scQcDZrIawI-OLj0w1g_51lBpG7etq6qWfvIXUC6wN_Aj0cU45Pm9lhgGXOoKOBm1fr-1-1cx8rinY5-8wd1QrVsqffrKbrIce-DsvzhdmgErMEfx_1RkK56ClQVEi3jDs5GTHdXQIgNZa_UeGU4w0ekCo4Se-slMzyGFfh9VEnS_EozIqUNbEnwuTDqG8gYN2yun65nbyePw0IR1cyC8zLf_OdYS94mi9R1CNHVGtZg

// first part of the JWT is the header 
var header = "eyJhbGciOiJSUzI1NiIsImtpZCI6Im1pY3Jvcy9oYy1ib3QtbWFuYWdlci9wc2hhaC1hZXNvODlpdmJqMjJiaGczIiwidHlwIjoiSldUIn0"

const  decoded_header = {
  "alg": "RS256",
  "kid": "micros/hc-bot-manager/pshah-aeso89ivbj22bhg3",
  "typ": "JWT"
}

// second part of the JWT is the payload data 

var payload_data = "eyJhdWQiOiJpZGVudGl0eS1wbGF0Zm9ybSIsImV4cCI6MTUwMjMyMzA2MywiaWF0IjoxNTAyMzIzMDMzLCJpc3MiOiJtaWNyb3MvaGMtYm90LW1hbmFnZXIiLCJqdGkiOiI2OWIxNTMxMS1jMWExLTQ3MGEtYTY5Yi0xM2IzNDQxNDQ4OTUifQ"

var decoded_payload = {
  "aud": "identity-platform",
  "exp": 1502323063,
  "iat": 1502323033,
  "iss": "micros/hc-bot-manager",
  "jti": "69b15311-c1a1-470a-a69b-13b344144895"
}


// third part of the JWT is the signature 

var signature = "jFf5wgOSOWGP3X62iwkku-u3ss5uEgd1fbPjw_MMFOpvXqX8AS_vAir1AhWA1IYNPBm_azo2syYBeIEK7xu-92hcFDGeM_nhAz27p6L693scQcDZrIawI-OLj0w1g_51lBpG7etq6qWfvIXUC6wN_Aj0cU45Pm9lhgGXOoKOBm1fr-1-1cx8rinY5-8wd1QrVsqffrKbrIce-DsvzhdmgErMEfx_1RkK56ClQVEi3jDs5GTHdXQIgNZa_UeGU4w0ekCo4Se-slMzyGFfh9VEnS_EozIqUNbEnwuTDqG8gYN2yun65nbyePw0IR1cyC8zLf_OdYS94mi9R1CNHVGtZg"
var signature_decoded = ""