【问题标题】:AWS Cognito with Lambda for custom validationAWS Cognito 与 Lambda 用于自定义验证
【发布时间】:2017-08-19 02:18:49
【问题描述】:

将 AWS Lambda 与 Cognito 结合使用,我们可以使用以下代码自动验证电子邮件。

event.response.autoConfirmUser = true;
event.response.autoVerifyEmail = true;

如何在此处进行自定义请求验证?

如果我想在 cognito 注册时发送促销代码,那么我可以有一个代码来验证这个促销代码,如果它是无效的促销代码,则拒绝注册请求。

【问题讨论】:

    标签: aws-lambda aws-cognito


    【解决方案1】:

    搞定了:-)

    exports.handler = (event, context, callback) => {
        //Auto confirming user and verifying emaail
        event.response.autoConfirmUser = true;
        event.response.autoVerifyEmail = true;
        //Extract Registration code from user attributes 
        var rCode = event.request.userAttributes["custom:rCode"];
        var validRCode = "abcdef";
        if (rCode && rCode.toLowerCase() != validRCode) {
             //If registration code is available and it is not equal to validRCode then throw error message
             var error = new Error(': Invalid registration code used.');
             context.done(error, event);
        } else {
          context.done(null, event);
        }
    };
    

    【讨论】:

    • 不幸的是,这不再起作用了。我已经测试了所有适当的触发器来尝试限制用户注册,并且几乎没有干净的方法可以阻止用户注册,特别是如果您有联合池并使用 Amplify。 Cognito 触发器钩子非常基础,因此唯一的方法是通过 SDK 使用 Lambda 和 Cognito 提供您自己的 API。
    【解决方案2】:

    您可以设置触发器来自定义 UserPool 工作流程:http://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html

    在您的情况下,设置 预注册 触发器应该没问题。

    【讨论】:

    • 我觉得从问题的前提来看,Shashwat Tripathi 在文档中读到了这么远。
    猜你喜欢
    • 2017-03-12
    • 2019-08-07
    • 1970-01-01
    • 2020-08-24
    • 2018-05-19
    • 2021-03-23
    • 2021-04-22
    • 2018-11-13
    • 2019-06-19
    相关资源
    最近更新 更多