- Newest
- Most votes
- Most comments
This is a common challenge with AWS Cognito and API Gateway JWT authorizers. Let me help you with a few potential solutions:
-
Using Resource Server Identifier:
{ "UserPoolId": "your-user-pool-id", "ResourceServer": { "Identifier": "https://api.yourdomain.com", "Name": "your-resource-server" } }
When you create a resource server in Cognito, its identifier becomes the audience in the tokens. You can:
Set a single, generic identifier for your resource server
Use this same identifier in the JWT authorizer's audience field
All client credentials tokens will then contain this audience
2. Custom Solution with Lambda Authorizer: If the JWT authorizer limitations are too restrictive, you can switch to a Lambda authorizer:
exports.handler = async (event) => { const token = event.headers.authorization; // Verify token using cognito-jwt-verify or similar // Implement your own audience validation logic return { isAuthorized: true, context: { // Additional context if needed } }; };
-
Update Token Configuration: You can modify the OAuth2.0 scopes and token configuration in your app client settings:
aws cognito-idp update-resource-server
--user-pool-id your-user-pool-id
--identifier your-identifier
--name your-resource-server-name
--scopes ScopeName=your-scope,ScopeDescription=description
If you absolutely need to avoid audience validation:
Consider using a Lambda authorizer instead of JWT authorizer
Use token scopes for authorization instead of audience
Implement custom validation logic based on other token claims

I created a resource server with an identifier of "my-sample-api-identifier" and a custom scope "access". In my App Client registration in "Edit managed login pages configuration" I added the custom scope to "Custom scopes". Then I requested an access token from the token endpoint using the custom scope. I inspected the access token, but there is no "aud" attribute. So it seems that 1. potential solution does not work? Or am I missing a piece?