-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CognitoCurrentUser() produces "Validation Error for Claims" #27
Comments
An alternative solution could also parse the "sub" uuid and scopes('cognito:groups') from the Access Token Payload, and make username/email optional. I found some claims contents documentation: https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-with-identity-providers.html#amazon-cognito-user-pools-using-the-access-token |
By the way: I've managed to work around this using a custom CognitoClaim object. 💪 |
I thought of another possibility that might help:
The A combination of this with |
@mjvdvlugt Always thank you for your feedback and proposals. Very helpful !!! I would like to investigate a little further whether to make it the default configuration. |
A small note - if you want to avoid modifying the package code you'll also need to create a custom
Otherwise the CognitoCurrentUser instance will by default use the original version of CognitoClaims which only provide the username and string. With this approach instead you get all claims. |
When using
CognitoCurrentUser(region=settings.aws_region, userPoolId=settings.aws_cognito_user_pool_id)
in my endpoint depencies, it consistently errors a 403: "Validation Error for Claims". Further investigation indicated this has to do with an issue mapping the Cognito reply to the CognitoClaims Pydantic model here:fastapi-cloudauth/fastapi_cloudauth/base.py
Line 232 in a8db880
The ValidationError is:
and indeed, the 'cognito:username' field is not available in the claims:
but 'username' is!
I wasn't able to find why Cognito returns the claims in this different way.
Proposed compatibility fix
Adding the
allow_population_by_field_name = True
in the CognitoClaims model config makes it compatible with this other Cognito output.The text was updated successfully, but these errors were encountered: