Skip to content

Commit

Permalink
Merge pull request #75 from kinde-oss/fix/audiencecheck
Browse files Browse the repository at this point in the history
fix: audience check when checking specific
  • Loading branch information
DanielRivers authored Sep 27, 2024
2 parents 6036573 + be35291 commit 35cf719
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/utils/isTokenValid/isIDTokenValid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ describe('isIDToken valid', () => {
);
});

test("Extra aud values don't throw", () => {
expect(
isTokenValid(
{
header,
payload: {
...idTokenStub,
aud: ['https://account.acme.com', '123456789']
}
},
config
)
).toBe(true);
});

test('Throw error if token expired', () => {
expect(() => {
isTokenValid(
Expand Down
12 changes: 7 additions & 5 deletions src/utils/isTokenValid/isTokenValid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ const isTokenValid = (token: any, config: any) => {
throw new Error('(aud) claim must be an array');
}

if (
!token.payload.aud.every((element: string) =>
config.aud.includes(element)
)
) {
const configAud = config.aud.split(' ');

const allConfigAudExistInPayload = configAud.every((element: string) =>
token.payload.aud.includes(element)
);

if (!allConfigAudExistInPayload) {
throw new Error(
`(aud) claim mismatch. Expected: "${
config.aud
Expand Down

0 comments on commit 35cf719

Please sign in to comment.