Skip to content

Commit

Permalink
Merge pull request #70 from rudolf-erasmus/bugfix/fix-multiple-aud-error
Browse files Browse the repository at this point in the history
Changed audience check to check against each configured audience, updated tests
  • Loading branch information
DaveOrDead authored Jun 12, 2024
2 parents e527108 + d3a2644 commit 2471750
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/utils/isTokenValid/isIDTokenValid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {isTokenValid} from './isTokenValid';

const config = {
iss: 'https://account.acme.com',
aud: 'https://account.acme.com',
aud: 'https://account.acme.com 123456789',
azp: '123456789'
};

Expand Down Expand Up @@ -111,7 +111,7 @@ describe('isIDToken valid', () => {
config
);
}).toThrow(
`(aud) claim mismatch. Expected: "https://account.acme.com", Received: "mate"`
`(aud) claim mismatch. Expected: "https://account.acme.com 123456789", Received: "mate"`
);
});

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

if (!token.payload.aud.includes(config.aud)) {
if (
!token.payload.aud.every((element: string) =>
config.aud.includes(element)
)
) {
throw new Error(
`(aud) claim mismatch. Expected: "${
config.aud
Expand Down

0 comments on commit 2471750

Please sign in to comment.