feat(std/jwt): add a JSON Web Token library (#7991)

Co-authored-by: Tim Reichen <timreichen@users.noreply.github.com>
This commit is contained in:
timonson 2020-10-20 05:08:34 +02:00 committed by GitHub
parent 992c2a436e
commit 034ab48086
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 739 additions and 0 deletions

17
std/jwt/_algorithm.ts Normal file
View file

@ -0,0 +1,17 @@
/*
* JSW §1: Cryptographic algorithms and identifiers for use with this specification
* are described in the separate JSON Web Algorithms (JWA) specification:
* https://www.rfc-editor.org/rfc/rfc7518
*/
export type Algorithm = "none" | "HS256" | "HS512";
export type AlgorithmInput = Algorithm | Array<Exclude<Algorithm, "none">>;
/**
* Verify the algorithm
* @param algorithm as string or multiple algorithms in an array excluding 'none'
* @param the algorithm from the jwt header
*/
export function verify(algorithm: AlgorithmInput, jwtAlg: string): boolean {
return Array.isArray(algorithm)
? (algorithm as string[]).includes(jwtAlg)
: algorithm === jwtAlg;
}