【问题标题】:The autoVerifyEmail on PreSignUp trigger does not verify the new user's emailPreSignUp 触发器上的 autoVerifyEmail 不会验证新用户的电子邮件
【发布时间】:2021-07-07 20:36:26
【问题描述】:

我使用 admin_create_user 触发 PreSignUp lambda:

        self.cognito.admin_create_user(
            UserPoolId=self.user_pool_id,
            Username=user.username,
            UserAttributes=[
                {
                    'Name': 'name',
                    'Value': user.username
                },
                {
                    'Name': 'email',
                    'Value': user.username
                },
            ],
            MessageAction='SUPPRESS')

使用此处理程序触发 lambda:

def pre_signup(event, context):

    event['response']['autoConfirmUser'] = True
    event['response']['autoVerifyEmail'] = True
    
    print(f"EVENT: {event}")
    return event

然后在 Cloudwatch 上,事件是(敏感数据已被隐藏):

EVENT: {'version': '1', 'region': 'us-east-X', 'userPoolId': 'us-east-X_XXXXXXXX', 'userName': 'XXXXXXXX-bd2d-4fec-b421-d2c4b89f3274', 'callerContext': {'awsSdkVersion': 'aws-sdk-unknown-unknown', 'clientId': 'CLIENT_ID_NOT_APPLICABLE'}, 'triggerSource': 'PreSignUp_AdminCreateUser', 'request': {'userAttributes': {'name': 'XXXXXXXXXX@XXXXXXXX.com', 'email': 'XXXXXXXXXX@XXXXXXXX.com'}, 'validationData': None}, 'response': {'autoConfirmUser': True, 'autoVerifyEmail': True, 'autoVerifyPhone': False}}

如您所见,autoVerifyEmail 选项设置为 True,just as the docs state。问题是,这东西坏了,它就是不工作。

即使手动调用admin_update_user_attributes 也不起作用。

    self.cognito.admin_update_user_attributes(
            UserPoolId=self.user_pool_id,
            Username=user.username,
            UserAttributes=[
                {
                    'Name': 'email_verified',
                    'Value': True
                },
            ]
        )

Even in the AWS forums there are no answers。那么,这件事是完全坏了还是我做错了什么?我什至尝试设置为字符串 'true' 只是因为文档上的引号('boolean')。我不知道该怎么办了,用户没有通过验证的电子邮件属性创建。

【问题讨论】:

    标签: python amazon-web-services boto3 amazon-cognito


    【解决方案1】:

    对于那些将来会遇到这种情况的人,我已经用admin_update_user_attributes 解决了它,值必须是一个字符串。

    admin_update_user_attributes_response = self.cognito.admin_update_user_attributes(
            UserPoolId=self.user_pool_id,
            Username=user.username,
            UserAttributes=[
                {
                    'Name': 'email_verified',
                    'Value': 'true'
                },
            ]
        )
    

    原来这是我的错误,我没有测试正确的端点,所以我在 cloudwatch 上看不到这个变化。很难测试与 AWS Cognito 相关的任何内容,它不是一项非常用户友好的服务。

    【讨论】:

      猜你喜欢
      • 2018-08-14
      • 1970-01-01
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      • 2019-07-05
      相关资源
      最近更新 更多