首页 文章

在AWS Cognito中 - 如何仅允许特定电子邮件地址注册?

提问于
浏览
5

我在javascript中使用AWS Cognito与amazon-cognito-identity-js包,它一直很棒 .

I am wondering, how is it possible to only allow users with certain email address endings to go through the signup flow?

例如,只有输入以.... @ companyABC.com结尾的电子邮件地址的人才可以注册并获取发送到该电子邮件地址的确认码 . 这将阻止公司外部的人访问该应用程序 . 该应用程序没有任何绝密信息,但我们只希望公司内的用户访问它 .

我期待用户池设置和在线,但无法找到解决方案 .

谢谢!

4 回答

  • 0

    您可以使用Pre Sign Up Lambda触发器检查用户的电子邮件,然后接受或拒绝注册请求,more info.

  • 5

    Cognito具有各种“触发器”,可以使用Lambda调用以允许自定义处理 . 您可以尝试使用预登记触发器中的Chris登录吗?

  • -3

    我能够通过预注册lambda触发器来实现这一点,但是找不到使用配置限制访问的方法 .

    这是我的lambda函数代码

    exports.handler = (event, context, callback) => {
        console.log ("Trigger function =", event.triggerSource);
    
        // Send post authentication data to Cloudwatch logs
        if (event.request.userAttributes.email.endsWith('@mydomain.com')) {
                console.log ("Authentication successful: ", event.request);
                callback(null, event);
        } else {
            console.log ("Authentication failed: ", event.request);
            callback("can't connect to admin", event)
        }
    
    };
    
  • 0

    如果使用角度2

    <input
            type="text" class="form-control" id="loginEmail"
            required
            pattern="^[a-zA-Z0-9]*(@companyABC.com)$"
            [(ngModel)]="email" name="loginEmail"
            #loginEmail="ngModel">
    

    https://regex101.com/r/Y6P47P/3

相关问题