An open API service indexing awesome lists of open source software.

https://github.com/everettmorgan/jwt

My implementation of the JWT rfc spec.
https://github.com/everettmorgan/jwt

jwt node

Last synced: 4 months ago
JSON representation

My implementation of the JWT rfc spec.

Awesome Lists containing this project

README

          

# ejmorgan-jwt

A simple implementation of the JWT rfc spec.

## Usage

```javascript
const JWT = require("ejmorgan-jwt");

const jwt = JWT.New({
key: 'my-key',
header: {
alg: "sha256",
},
payload: {
aud: "audience",
custom: "my-key",
},
});

const str = jwt.toString();

console.log(str);
// eyJhbGciOiJzaGEyNTYifQ.eyJhdWQiOiJhdWRpZW5jZSIsImN1c3RvbSI6Im15LWtleSJ9.bY7PCElW5f245tSaLVkiGIfLBISU7kdyfCniJ62FsDM=

const [err, ajwt]= JWT.Read(str, 'my-key');

console.log(ajwt);
// JSONWebToken {
// header: { alg: 'sha256' },
// payload: { aud: 'audience', custom: 'my-key' },
// signature: 'bY7PCElW5f245tSaLVkiGIfLBISU7kdyfCniJ62FsDM='
// }

ajwt.payload.aud = 'hehehe';

const ok = JWT.Validate(ajwt, 'my-key');

console.log(ok);
// false
```