@edwin254-byte/token
v1.1.3
Published
Decodes token using jwks
Downloads
9
Readme
TOKEN DECODER USING JWKS AND JWT
HOW TO INSTALL
$ npm i @edwin254-byte/token
USAGE
const decodeToken = require("@edwin254-byte/token");
async function main(){
try{
const token = "<REPLACE WITH YOUR TOKEN>";
const jwks = await <"FETCH YOUR JWKS">
await decodedToken =await decodeToken(token,jwks)
if(!decodedToken) throw new Error("Some went wrong")
console.log(decodedToken)
} catch(e){
console.log(e)
}
}
EXAMPLE
const decodeToken = require("@edwin254-byte/token");
async function main() {
try{
const token =
"eyJ0eXAiOiJqd3QiLCJhbGciOiJFUzM4NCIsImtpZCI6IjVTOW9GdEhvVE9fdS1taDhTbnF6Tnc1SURUdnI5T3N5SnJBY2xIME5PWXMifQ.eyJleHAiOjE2NzE2MTcxMzIsImlhdCI6MTY3MTYxMzUzMiwic3ViIjoidXNlcjAwMUBnbWFpbC5jb20iLCJwaG9uZU5vIjoiMDcxMjM0NTY3ODkifQ.y7IvxtZJJX3g765Fj-92LOciSHCq9_3J8aJWiAweoMMlmrMJ6w-UFymroZIJ6rLFWeWc6gauoyO9kkjzdjB-w1HHOmYl72TfexWrrfrm73gKvBl1P18o5snTmBrjC-Qw";
const resData = await fetch("http://192.168.86.10:4000/jwks");
const jwks = await resData.json();
const decodedToken = await decodeToken(token, jwks);
if(!decodedToken) throw new Error("Something went wrong")
console.log(decodedToken);
}catch(e){
console.log(e)
}
}
main();
OUTPUT
If token is valid and not expired
{
exp: 1671617132,
iat: 1671613532,
sub: '[email protected]',
phoneNo: '07123456789'
}
Else
{ error: 'Provided token is expired!' }