diff options
author | timonson <54777088+timonson@users.noreply.github.com> | 2020-10-20 05:08:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-20 14:08:34 +1100 |
commit | 034ab48086557af00216ffe311c71ad4eb0ec4d5 (patch) | |
tree | 292abc572ed68eb52c1bc773e64f820497e065df /std/jwt/_algorithm.ts | |
parent | 992c2a436e5fe371807dd43bd293bb811fd529e7 (diff) |
feat(std/jwt): add a JSON Web Token library (#7991)
Co-authored-by: Tim Reichen <timreichen@users.noreply.github.com>
Diffstat (limited to 'std/jwt/_algorithm.ts')
-rw-r--r-- | std/jwt/_algorithm.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/std/jwt/_algorithm.ts b/std/jwt/_algorithm.ts new file mode 100644 index 000000000..c9c5257e1 --- /dev/null +++ b/std/jwt/_algorithm.ts @@ -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; +} |