0.1.1 • Published 12 months ago

@sqrls/tinyjwt v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

tinyjwt

A little scrappy JWT helper.

Use

Add keys. Sign or verify. Sorta fits RFC7519. Only supports sha256. Example (TypeScript):

import { sign, verify } from "@sqrls/tinyjwt"

// Sign with a secret key and key ID
const signedJwt = sign({ sub: "bob", exp: Date.now() + 23, other: "data" }, "super secret", "key id");

// And verify
const contents = tinyjwt.verify(signedJwt, (keyId) => {
    if (keyId === "key id") return "super secret";
});

// If contents are undefined, verification failed
if (!contents) {
    throw new Exception("Invalid!")
}

// Don't care about key IDs? They're optional
const jwt = sign({ sub: "bob", exp: Date.now() + 23, other: "data" }, "super secret");
const contents = verify(jwt, () => "super secret");

If either exp or nbf are present, they are checked and the JWT rejected appropriately.

0.1.1

12 months ago

0.1.0

12 months ago