Skip to content

Repository files navigation

webcrypto-jwt

JSON Web Tokens (JWT) verify/sign implementation using W3C Web Cryptography (crypto.subtle).

Browser Support

The following browsers are supported without shims: IE TP, Firefox 35+ and Chrome 37+. Safari is not currently working. For more information about compatiblity check web cryptography browser support.

Install

With npm:

npminstallwebcrypto-jwt

or with bower:

bowerinstallwebcrypto-jwt

and then add the following script tag:

<scriptsrc="webcrypto-jwt/index.js"></script>

Usage

JWT verification and decoding:

varjwt=require('webcrypto-jwt');// token signed using 'secret' as secretvartoken='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.'+'eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.'+'TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ';jwt.verifyJWT(token,'secret','HS256',function(err,isValid){console.log(isValid);// true});jwt.verifyJWT(token,'nosecret','HS256',function(err,isValid){console.log(isValid);// false});jwt.decodeJWT(token);// '{"sub":"1234567890","name":"John Doe","admin":true}'jwt.parseJWT(token)// Object {sub: "1234567890", name: "John Doe", admin: true}

JWT signing:

varsignJWT=require('webcrypto-jwt').signJWT;signJWT({foo: 'bar'},'secret','HS256',function(err,token){// ey...console.log(token);});

About

JSON Web Tokens (JWT) verify/sign implementation using W3C Web Cryptography (crypto.subtle).

Resources

Stars

32 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages