Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
feat: allow regex in SMARTConfig.expectedAudValue (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
carvantes authored Jul 9, 2021
1 parent c644cb7 commit 2442856
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/smartAuthorizationHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,20 @@ describe('verifyJwt', () => {
verifyJwtToken(jwt, expectedAudValue, 'https://exampleAuthServer.com/oauth2', client),
).resolves.toEqual(payload);
});

test('aud provided as RegExp', async () => {
const aud = 'api://default';
const audRegExp = /api:\/\/([a-z])+/;

const payload = getDefaultPayload(
Math.floor(Date.now() / 1000),
Math.floor(Date.now() / 1000) + 10,
aud,
expectedIssValue,
);
const jwt = await getSignedJwt(payload);
return expect(verifyJwtToken(jwt, audRegExp, expectedIssValue, client)).resolves.toEqual(payload);
});
});

test('iss is incorrect', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/smartAuthorizationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function getJwksClient(jwksUri: string): JwksClient {

export async function verifyJwtToken(
token: string,
expectedAudValue: string,
expectedAudValue: string | RegExp,
expectedIssValue: string,
client: JwksClient,
) {
Expand Down
5 changes: 4 additions & 1 deletion src/smartConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ export interface SMARTConfig {
scopeRule: ScopeRule;
/**
* Per SMART spec this is the 'aud' key found in the access_token
*
* Using the string type is recommended. RegExp can be useful when the audience is not static, such as in multi-tenant setups.
* Caution must be taken to avoid overly permissive regular expressions (e.g. avoid using .*). Use regular expressions that are as specific as possible to avoid allowing requests from unexpected audiences.
*/
expectedAudValue: string;
expectedAudValue: string | RegExp;
/**
* Per SMART spec this is the 'iss' key found in the access_token
*/
Expand Down

0 comments on commit 2442856

Please sign in to comment.