Added test suite
This commit is contained in:
18
src/jwt.ts
18
src/jwt.ts
@ -1,7 +1,23 @@
|
||||
import {JSONAttemptParse} from './objects.ts';
|
||||
|
||||
/**
|
||||
* Decode a JWT payload, this will not check for tampering so be careful
|
||||
* Creates a JSON Web Token (JWT) using the provided payload.
|
||||
*
|
||||
* @param {object} payload The payload to include in the JWT.
|
||||
* @param signature Add a JWT signature
|
||||
* @return {string} The generated JWT string.
|
||||
*/
|
||||
export function createJwt(payload: object, signature = 'unsigned'): string {
|
||||
const header = Buffer.from(JSON.stringify({ alg: "HS256", typ: "JWT" }))
|
||||
.toString('base64url');
|
||||
const body = Buffer.from(JSON.stringify(payload))
|
||||
.toString('base64url');
|
||||
// Signature is irrelevant for decodeJwt
|
||||
return `${header}.${body}.${signature}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a JSON Web Token (JWT) payload, this will not check for tampering so be careful
|
||||
*
|
||||
* @param {string} token JWT to decode
|
||||
* @return {unknown} JWT payload
|
||||
|
Reference in New Issue
Block a user