Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.


Create a JWT Token

node v8.17.0
version: 6.0.0
const base64Url = require("base64-url") const crypto = require('crypto'); const header = base64Url.encode(JSON.stringify({alg: 'HS256', typ: 'JWT'})) // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 const payload = base64Url.encode(JSON.stringify({message: 'Hello London'})) // eyJtZXNzYWdlIjoiSGVsbG8gTG9uZG9uIn0 const content = `${header}.${payload}` // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiSGVsbG8gTG9uZG9uIn0 const secret = 'I wanna ride my bicycle'; const rawSignature = crypto .createHmac('sha256', secret) .update(content) .digest('base64') const signature = base64Url.escape(rawSignature) // dS1wlkIJH6k4KWuAAr9rRa5FmEBHu0kdjluCNdR2qyE const jwt = `${content}.${signature}` console.log(`jwt: ${jwt}`) //eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiSGVsbG8gTG9uZG9uIn0.dS1wlkIJH6k4KWuAAr9rRa5FmEBHu0kdjluCNdR2qyE

no comments

    sign in to comment