Skip to content

Commit

Permalink
Add the ability to provide arbitrary custom header claims
Browse files Browse the repository at this point in the history
  • Loading branch information
cwirving committed Jul 22, 2024
1 parent 51da4ac commit 0850760
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ test("signJWT() supports additional header claims", async () => {
const payload = { foo: "bar", baz: 42 };
const jwtString = await signJWT(payload, privateKey, {
algorithm: algorithm,
additionalHeaderClaims: { typ: "JOSE", kid: "abc123" },
additionalHeaderClaims: { typ: "JOSE", kid: "abc123", someOther: [1, 2, 3] },
});

const unsafeHeader = unsafeParseJOSEHeader(jwtString);
Expand All @@ -145,7 +145,7 @@ test("signJWT() supports additional header claims", async () => {

assertEquals(unsafePayload, payload);
assertEquals(decodedPayload, payload);
const expectedHeader: JOSEHeader = { alg: algorithm, typ: "JOSE", kid: "abc123" };
const expectedHeader: JOSEHeader = { alg: algorithm, typ: "JOSE", kid: "abc123", someOther: [1, 2, 3] };
assertEquals(unsafeHeader, expectedHeader);
});

Expand Down
6 changes: 6 additions & 0 deletions src/standardclaims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export interface JOSEHeader {
* (see RFC 7519 section 5.1, RFC 7515 section 4.1.9, RFC 7516 section 4.1.11)
*/
typ?: string;

/**
* Allows for the inclusion of other header properties with string keys and values of any type.
*/
// deno-lint-ignore no-explicit-any
[key: string]: any;
}

/**
Expand Down

0 comments on commit 0850760

Please sign in to comment.