简体   繁体   English

如何在不验证电子邮件或电话的情况下确认 Cognito 用户池中的用户?

[英]How to confirm user in Cognito User Pools without verifying email or phone?

I am using Amazon Cognito Identity SDK for JavaScript (deprecated).我正在使用 适用于 JavaScript 的 Amazon Cognito 身份开发工具包(已弃用)。

I created new pool without verifying email and phone_number.我在没有验证电子邮件和电话号码的情况下创建了新池。

By default, users aren't confirmed in Cognito User Pools, so I need to do this manually.默认情况下,不会在 Cognito 用户池中确认用户,因此我需要手动执行此操作。

How to confirm user in Cognito User Pools without verifying email or phone?如何在不验证电子邮件或电话的情况下确认 Cognito 用户池中的用户?

I hope this will help someone else. 我希望这会帮助别人。

To do this you can add this Lambda function: 为此,您可以添加此Lambda函数:

exports.handler = (event, context, callback) => {
    event.response.autoConfirmUser = true;
    event.response.autoVerifyEmail = true;  // this is NOT needed if e-mail is not in attributeList
    event.response.autoVerifyPhone = true;  // this is NOT needed if phone # is not in attributeList
    context.done(null, event);
};

Then navigate to AWS Cognito's General settings >> Triggers and add this Lambda function to 'Pre sign-up' - click the drop down list and select Lambda function with above code. 然后导航到AWS Cognito的常规设置>>触发器并将此Lambda函数添加到“预注册” - 单击下拉列表并选择带有上述代码的Lambda函数。

If you only use 'preferred_username' (if no e-mail or phone # is used) setting event.response.autoConfirmUser to true is sufficient. 如果您只使用'preferred_username'(如果没有使用电子邮件或电话号码),则将event.response.autoConfirmUser设置为true即可。

Actually, AWS has recently added the ability to verify email and verify phone number in the pre-signup lambda as well. 实际上,AWS最近还添加了验证电子邮件和验证预注册 lambda中的电话号码的功能 You basically need to set autoVerifyEmail and autoVerifyPhone in the lambda and they will get verified. 你基本上需要在lambda中设置autoVerifyEmailautoVerifyPhone ,他们将得到验证。 More info in the official documentation . 官方文档中的更多信息。

"response": {
    "autoConfirmUser": boolean
    "autoVerifyEmail": boolean
    "autoVerifyPhone": boolean
}

I think the accepted answer is problematic.我认为接受的答案是有问题的。 OP's question is how to confirm a user without verifying their email . OP 的问题是如何在不验证用户电子邮件的情况下确认用户。 But the solution will verify the user's email.但该解决方案验证用户的电子邮件。

If you want to confirm a user with an unverified email (or phone), you can use AdminConfirmSignUpCommand .如果您想使用未经验证的电子邮件(或电话)确认用户,您可以使用AdminConfirmSignUpCommand It is the intended way to confirm a user without having them do it, as per official docs:根据官方文档,这是在不让用户这样做的情况下确认用户的预期方式:

在此处输入图片说明

Unlike ConfirmSignUpCommand , AdminConfirmSignUpCommand doesn't need a code.ConfirmSignUpCommand不同, AdminConfirmSignUpCommand不需要代码。 You can implement this command after signup in your API or as a Custom Message Trigger (effectively confirming the user when the email is sent).您可以在 API 中注册后或作为自定义消息触发器(在发送电子邮件时有效确认用户)后实施此命令。

Now, the user can log in, but the email must be confirmed still.现在,用户可以登录,但仍必须确认电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM