Skip to content
Myr

fix(jwt): Make JWT Header `typ` Field Optional to Enhance Compatibility (#2488)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* chore(utils/jwt): change typ parameter optional * chore(deno_dist): run denoify * chore(utils/jwt): add test case

authored by naporitan · committed by GitHub · parent 19ef40d · Browse files · 3 files+21 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+21 added−6 removed

  • tests:+17 added−0 removed
  • other:+4 added−6 removed

3 files+21 added−6 removed

modified:deno_dist/utils/jwt/jwt.ts+2 added-3 removed
modified:src/utils/jwt/jwt.test.ts+17 added
28 unmodified lines
29 }3031 expect(JWT.isTokenHeader(invalidTokenHeader)).toBe(false)32 })3334 it('returns true even if the typ field is absent in a TokenHeader', () => {35 const validTokenHeader: JWT.TokenHeader = {36 alg: AlgorithmTypes.HS256,37 }3839 expect(JWT.isTokenHeader(validTokenHeader)).toBe(true)40 })4142 it('returns false when the typ field is present but empty', () => {43 const invalidTokenHeader = {44 alg: AlgorithmTypes.HS256,45 typ: '',46 }4748 expect(JWT.isTokenHeader(invalidTokenHeader)).toBe(false)49 })50})5152describe('JWT', () => {53 it('JwtAlgorithmNotImplemented', async () => {
444 unmodified lines
modified:src/utils/jwt/jwt.ts+2 added-3 removed
20 unmodified lines
21 JSON.parse(utf8Decoder.decode(decodeBase64Url(part)))2223export interface TokenHeader {24 alg: SignatureAlgorithm25 typ: 'JWT'25 typ?: 'JWT'26}2728// eslint-disable-next-line29export function isTokenHeader(obj: any): obj is TokenHeader {
1 unmodified line
31 typeof obj === 'object' &&32 obj !== null &&33 'alg' in obj &&34 Object.values(AlgorithmTypes).includes(obj.alg) &&35 'typ' in obj &&36 obj.typ === 'JWT'35 (!('typ' in obj) || obj.typ === 'JWT')36 )37}3839export const sign = async (
69 unmodified lines