Skip to content

fix(parser): accept Cognito pre token generation V2 and V3 events - #8863

Open
Manishram-ai wants to merge 1 commit into
aws-powertools:developfrom
Manishram-ai:fix/parser-cognito-pre-token-v2-scopes
Open

Manishram-ai wants to merge 1 commit into
aws-powertools:developfrom
Manishram-ai:fix/parser-cognito-pre-token-v2-scopes

Conversation

@Manishram-ai

Copy link
Copy Markdown
Contributor

Issue number:
closes #8861

Summary

Changes

  • CognitoPreTokenGenerationRequestModelV2AndV3.scopes is now list[str] | None. Cognito sends scopes as a list of strings, so the old dict type rejected every V2 and V3 event that had them.
  • CognitoPreTokenGenerationTriggerModelV2AndV3 now has triggerSource: str, the same as CognitoPreTokenGenerationTriggerModelV1 and the other Cognito trigger models.
  • The model had no tests. cognitoPreTokenV2GenerationEvent.json, already in tests/events, is now in the parse test list, and a new test checks scopes and triggerSource.

User experience

Before, parsing a V2 or V3 pre token generation event failed with Input should be a valid dictionary for request.scopes, so the model couldn't be used with events from Cognito. Now they parse, parsed.request.scopes is the list Cognito sent, and parsed.triggerSource says which flow invoked the function, for example TokenGeneration_RefreshTokens.

About ADR 0006, the model now rejects a dict scopes and an event without triggerSource, which it accepted before. Cognito sends neither, so this only changes things for hand-written events. I treated it as a fix to match the AWS contract, like #8793 did for the VPC Lattice V2 list values. If you'd rather keep accepting those inputs with a PowertoolsUserWarning until the next major, I'm happy to change it.

Verification

  • Both new tests fail on develop with Input should be a valid dictionary and pass with this change.
  • tests/unit/parser and tests/functional/parser: 274 passed on Python 3.10, 3.12 and 3.14 (272 on develop).
  • tests/unit: 703 passed, 1 skipped. tests/performance and the Cognito data class tests pass.
  • ruff format --check, ruff check and mypy aws_lambda_powertools examples are clean.
  • I didn't run this against a live user pool. The event shape comes from the Cognito docs linked in the issue and the V2 event already in tests/events.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@Manishram-ai
Manishram-ai requested a review from a team as a code owner November 17, 2026 03:51
@Manishram-ai
Manishram-ai requested a review from svozza November 17, 2026 03:51
@boring-cyborg boring-cyborg Bot added the tests label Nov 17, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 17, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: CognitoPreTokenGenerationTriggerModelV2AndV3 rejects V2 and V3 events because scopes is a list

1 participant