markomirosavljev / fastapi-cognito

Basic Cognito-Auth library for Python and FastAPI.
MIT License
53 stars 17 forks source link

Support cognito custom user attributes #16

Closed onejgordon closed 5 months ago

onejgordon commented 1 year ago

Thank you for this library!

AWS Cognito custom user attributes, necessarily, I believe, start with the custom: prefix. It does not appear that it's possible to use this as an attribute in the subclass of CognitoToken, due to the colon.

class CustomTokenModel(CognitoToken):
    custom_value: Optional[str] = None

Do you know if this is possible?

markomirosavljev commented 1 year ago

Hello, Im not sure but I think that might be possible with alisases in custom model. By default, models should be populated by alias if alias is defined, else it will use field name. You can check in pydantic documentation

At the moment I don't have time to test this, but as soon as I test this behavior, I will report here. :blush:

Also, if you test it in the meantime, please comment here if you achieved the wanted behavior :blush:

markomirosavljev commented 5 months ago

This is possible with current implementation thanks to custom token models and pydantic aliases. I'll add example in docs in next release.