我使用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);
答案 0 :(得分:0)
目前Cognito不支持此用例,因为客户需要登录才能更新电话号码,未经证实的帐户无法登录。 一种选择是让用户使用正确的电子邮件地址创建一个新帐户。另一个选择是最终用户联系开发人员,开发人员可以使用AdminUpdateUserAttributes来更新用户电话号码。