Skip to content

Commit bdcc89a

Browse files
committed
fix(auth): support wildcard audience validation for OAuth providers without aud claim
The JWT validator's wildcard audience feature (audience: '*') was not working as documented. When configured with audience: '*', the validator still required tokens to have an aud claim, preventing Dynamic Client Registration (DCR) from working with OAuth providers that don't include aud in access tokens (e.g., AWS Cognito which uses client_id instead). Changes: - Make audience validation conditional in jwt.verify() options - Only require aud claim when config.audience !== '*' - Update debug logging to handle tokens without aud claim This enables full DCR support for all RFC-compliant OAuth 2.0/2.1 providers.
1 parent 3ac5fc7 commit bdcc89a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/auth/validators/jwt-validator.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,15 @@ export class JWTValidator {
107107
return new Promise((resolve, reject) => {
108108
const options: VerifyOptions = {
109109
algorithms: this.config.algorithms as jwt.Algorithm[],
110-
audience: this.config.audience,
111110
issuer: this.config.issuer,
112111
complete: false,
113112
};
114113

114+
// Only validate audience if not set to wildcard
115+
if (this.config.audience !== '*') {
116+
options.audience = this.config.audience;
117+
}
118+
115119
jwt.verify(token, publicKey, options, (err, decoded) => {
116120
if (err) {
117121
if (err.name === 'TokenExpiredError') {
@@ -147,7 +151,8 @@ export class JWTValidator {
147151
return;
148152
}
149153

150-
if (!claims.aud) {
154+
// Only require aud claim if not set to wildcard
155+
if (this.config.audience !== '*' && !claims.aud) {
151156
reject(new Error('Token missing required claim: aud'));
152157
return;
153158
}
@@ -157,9 +162,11 @@ export class JWTValidator {
157162
return;
158163
}
159164

160-
logger.debug(
161-
`Token claims validated - sub: ${claims.sub}, iss: ${claims.iss}, aud: ${Array.isArray(claims.aud) ? claims.aud.join(', ') : claims.aud}`
162-
);
165+
const audInfo = claims.aud
166+
? `aud: ${Array.isArray(claims.aud) ? claims.aud.join(', ') : claims.aud}`
167+
: 'aud: <not present - wildcard mode>';
168+
169+
logger.debug(`Token claims validated - sub: ${claims.sub}, iss: ${claims.iss}, ${audInfo}`);
163170
resolve(claims);
164171
});
165172
});

0 commit comments

Comments
 (0)