LiteRT/Tokens
A token serialization & unserialization library.
Requirement
- TypeScript v4.0.x (or newer)
- Node.js v12.0.0 (or newer)
Installation
npm i @litert/tokens --save
Usage
import * as Tokens from "@litert/tokens";
// Create a JWT encoder.
const jwts = Tokens.createJWTEncoder();
// Register a profile with HMAC-SHA-512 algorithm.
jwts.registerHMACProfile({
name: 'test-hs512',
algorithm: 'sha512',
key: 'hello world',
predefinedPayload: {
aud: 'https://litert.org'
},
predefinedHeaders: {
vid: 123456
}
});
// Create a JWT with hs512 profile.
const testJWT = jwts.create("test-hs512", {
"iss": "Heaven",
"name": "Hik"
});
// Print the JWT string.
console.log(testJWT);
// Try to verify it, if verified successfully, check the testInfo.signature.
const testInfo = jwts.verify(testJWT, "test-hs512");
if (testInfo.signature.verified) {
console.info("Success!");
}
else {
console.error("Failed!");
}
// Print the JWT structure.
console.log(JSON.stringify(testInfo, null, 2));
Document
Preparing yet.
License
This library is published under Apache-2.0 license.