Flutter 注册确认通过电话 otp 在 aws 放大

问题描述

如何通过电话 otp 而不是电子邮件 otp 添加电话和确认注册

解决方法

试试 amazon_cognito_identity_dart 包。

//Create a cognito user
CognitoUser cognitoUser1;

//Send OTP
 cognitoUser1 = CognitoUser(phoneNumber.text,widget.userPool);
  try {
    CognitoUserSession cognitoUserSession =
        await cognitoUser1.initiateAuth(
      AuthenticationDetails(
        authParameters: [
          AttributeArg(
            name: 'phone_number',value: phoneNumber.text,),],);
  } catch (cognitoUserCustomChallengeException) {}
  

//Authenticate the user
CognitoUserSession cognitoUserSession = await cognitoUser1.sendCustomChallengeAnswer(otp.text);

print("jwtToken " + cognitoUserSession.accessToken.jwtToken);
print("refreshToken " + cognitoUserSession.refreshToken.token);
,

如果我理解正确,您在使用 Cognito 时遇到了一些配置问题。
为了启用电话 OTP,您应该连接到 AWS,选择您的项目并转到

用户池 > 属性

并设置您的配置以使用电话和/或电子邮件。
那你必须去

用户池 > MFA 和验证

并选择电话号码作为要验证的属性。