Using module hmac256 to create JSON Web Token. A PR is wating for verification and comments.
const HMAC = require('hmac2256'); HmacSHA256 = function(token, secret) { var hmac = HMAC.SHA256(E.toArrayBuffer(secret)); return btoa(String.fromCharCode.apply(null, hmac.digest(E.toArrayBuffer(token)))).replace(/=+$/, ''); }; var header = { "alg": "HS256", "typ": "JWT"}; var data = { "id": 1337,"username": "john.doe"}; var secret = "My very confidential secret!"; var encodedHeader = btoa(JSON.stringify(header)); var encodedData = btoa(JSON.stringify(data)); var token = encodedHeader + "." + encodedData; var signature = HmacSHA256(token, secret); var jwt = (token+'.'+signature);
@MaBe started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Using module hmac256 to create JSON Web Token. A PR is wating for verification and comments.