繁体   English   中英

如何使用 Cognito 用户池注册用户 - 没有用户名和密码的 Amazon Web Services

[英]How to sign up a user with Cognito User Pool - Amazon Web Services without username and password

我正在使用 Amazon Web Services 对我的 iOS 应用程序的用户进行身份验证。 我有一个带有电话号码的屏幕注册。 当用户输入他的电话号码时,他会得到一个 OTP 代码,然后,他将在验证屏幕中输入该代码。 最后,验证无误后,App 推送到创建用户名和密码屏幕。 这就是我想要的。 但是,亚马逊网络服务仅提供注册方法如下:

AWSCognitoIdentityUserAttributeType * phone = [AWSCognitoIdentityUserAttributeType new];
phone.name = @"phone_number";
//phone number must be prefixed by country code
phone.value = @"+15555555555";
AWSCognitoIdentityUserAttributeType * email = [AWSCognitoIdentityUserAttributeType new];
email.name = @"email";
email.value = @"email@mydomain.com";

//register the user
[[pool signUp:@"username" password:@"password" userAttributes:@[email,phone] validationData:nil] continueWithBlock:^id _Nullable(AWSTask<AWSCognitoIdentityUserPoolSignUpResponse *> * _Nonnull task) {
    dispatch_async(dispatch_get_main_queue(), ^{
        if(task.error){
            [[[UIAlertView alloc] initWithTitle:task.error.userInfo[@"__type"]
                                        message:task.error.userInfo[@"message"]
                                       delegate:self
                              cancelButtonTitle:@"Ok"
                              otherButtonTitles:nil] show];
        }else {
            AWSCognitoIdentityUserPoolSignUpResponse * response = task.result;
            if(!response.userConfirmed){
                //need to confirm user using user.confirmUser:
            }
        }});
    return nil;
}];

如您所见,我必须在使用电话号码注册时创建用户名和密码。 但我想创建用户名并稍后通过。 谁能帮我解决这个问题? 谢谢!

自 2017 年 1 月 9 日起,Amazon Cognito 不支持您描述的流程。

如果您反转流程,您可以使用 Cognito 执行此操作:使用用户名、密码和电话号码注册 -> 应用用户收到验证码 -> 应用用户提交验证码 -> 应用用户注册/登录。

只有当他们使用的电话号码经过验证并且电话号码的“自动验证”已打开时,用户才能登录。

您还可以使用别名让您的用户使用他们的电话号码登录:http: //docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings -别名

暂无
暂无

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

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