Repository navigation
Closed
Labels
Description
The following process worked correctly with Powertools for AWS Lambda (Python) v3.8.0 and earlier, but since v3.9.0, the response in the returned raw_event no longer contains the custom claims.
I would like to avoid directly editing the raw_event dictionary. Is there any recommended way to add custom claims to the authentication token in v3.9.0 or later?
Here is a simplified version of my handler:
pre_token_generation.response.claims_scope_override_details.access_token_generation = {
'claimsToAddOrOverride': {
'custom_user_id': pre_token_generation.request.user_attributes['preferred_username'],
}
}
# Return the raw event
return pre_token_generation.raw_eventExpected Behaviour
■v3.8.0 raw_event example:
{
'version': '2',
'region': 'example-region-1',
...,
'response': {
'claimsAndScopeOverrideDetails': {
'idTokenGeneration': {
'claimsToAddOrOverride': {
'custom_user_id': 'user123'
}
},
'accessTokenGeneration': {
'claimsToAddOrOverride': {
'custom_user_id': 'user123'
},
'scopesToAdd': ['access:example_scope']
}
}
}
}
Current Behaviour
In this case, response is empty.
■v3.9.0 raw_event example:
{
'version': '2',
'region': 'example-region-1',
...,
'response': {}
}
Code snippet
pre_token_generation.response.claims_scope_override_details.access_token_generation = {
'claimsToAddOrOverride': {
'custom_user_id': pre_token_generation.request.user_attributes['preferred_username'],
}
}
# Return the raw event
return pre_token_generation.raw_eventPossible Solution
No response
Steps to Reproduce
We send the following request to this function.
{
"version": "2",
"region": "region",
"userPoolId": "example",
"userName": "example",
"triggerSource": "TokenGeneration_HostedAuth",
"request": {
"userAttributes": {
"sub": "example",
"email": "example@example.com",
"preferred_username": "example",
"family_name": "example",
"given_name": "example",
"phone_number": "example",
"custom:family_name_kana": "example",
"custom:given_name_kana": "example",
"custom:company_name": "example",
"custom:created_by": "test",
"custom:updated_by": "test"
}
},
"response": {}
}
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsComing soon
Activity
boring-cyborg commentedon Nov 10, 2025
Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link
nc-dirknilius commentedon Nov 10, 2025
I can confirm the issue as we were running into the same issue and found that by downgrading to 3.8 restores the expected behavior.
Handler code (adding all claims prefixed with
custom:):Example test failing (
pytest):anafalcao commentedon Nov 10, 2025
Hi @ogis-takeuchi and @nc-dirknilius! Thanks for reporting this issue! I've confirmed the bug exists in v3.9.0 through the latest.
Would you any of you be interested in submitting a PR? I'll add this to our backlog.
nc-dirknilius commentedon Nov 10, 2025
I checked briefly the code. I might be able to submit a PR with a fix as well as additional tests covering the usage.
nc-dirknilius commentedon Nov 10, 2025
Hi @anafalcao, PR is created and waiting for approval.
[-]Bug: Unable to add custom claims to authentication token with PowerTools v3.9.0 and later[/-][+]Bug: Unable to add custom claims to authentication token with Powertools v3.9.0 and later[/+]powertools-for-aws-oss-automation commentedon Nov 19, 2025
Warning
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.