繁体   English   中英

如何在用户通过身份验证之前编辑“AWS cognito”用户池中用户的电话号码?

[英]How can I edit a phone number of a user in user pool of `AWS cognito` before the user is authenticated?

我使用AWS cognito来验证用户的电话号码。 我遇到了一个问题:当用户输入他的详细信息时,我会将其发送给AWS。 AWS尝试将代码发送到用户的电话号码,但如果用户输入错误的号码AWS返回异常“无效的电话号码”。 所以我要求用户更新号码,但是当我尝试在AWS中更新它时,它们会返回exception用户未经过身份验证 ”。 用户刚刚注册后仍然无法确认,如何将号码更新为正确的号码? 这是我的代码:

                    // Create a CognitoUserAttributes object and add user attributes 
                    CognitoUserAttributes userAttributes = new CognitoUserAttributes();
                    // Add the user attributes. Attributes are added as key-value pairs 
                    // Adding user's given name. 
                    // Note that the key is "given_name" which is the OIDC claim for given name 
                    userAttributes.addAttribute("name", userName); 
                    userAttributes.addAttribute("family_name", userFamily); 
                    // Adding user's phone number 
                    userAttributes.addAttribute("phone_number", prepareValidPhoneNumberForAWS(userPhone));

                    SignUpHandler signupCallback = new SignUpHandler() 
                    {
                        int t=0;
                        @Override
                        public void onSuccess(CognitoUser cognitoUserUser, boolean userConfirmed, CognitoUserCodeDeliveryDetails cognitoUserCodeDeliveryDetails) 
                        {
                            // Sign-up was successful

                            // Check if this user (cognitoUser) has to be confirmed
                            if(!userConfirmed) 
                            {
                                t=0;
                                // This user has to be confirmed and a confirmation code was sent to the user
                                // cognitoUserCodeDeliveryDetails will indicate where the confirmation code was sent
                                // Get the confirmation code from user
                            }
                            else 
                            {
                                // The user has already been confirmed
                                t=1;
                            }
                        }

                        @Override
                        public void onFailure(Exception exception) 
                        {   
                            // Sign-up failed, check exception for the cause
                            exception.printStackTrace();
                        }

                    };
                    userPool.signUpInBackground(currentUser.getUser_id(),currentUser.getUuid(),userAttributes,null,signupCallback);

目前Cognito不支持此用例,因为客户需要登录才能更新电话号码,未确认的帐户无法登录。 一种选择是让用户使用正确的电子邮件地址创建一个新帐户。 另一个选择是最终用户联系开发人员,开发人员可以使用AdminUpdateUserAttributes来更新用户电话号码。

暂无
暂无

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

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