如何使用 AWS 在 flutter 中进行无密码登录

Pra*_*att 4 authentication amazon-web-services amazon-cognito flutter

我无法知道如何在 flutter 中使用 cognito 使用OTP进行无密码登录 。我只需要颤振代码方面的帮助,用于发送 OTP 并使用任何有效的 cognito/amplify 包回答身份验证挑战者。

Pra*_*att 5

我能够使用这个包:amazon_cognito_identity_dart_2

//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);
Run Code Online (Sandbox Code Playgroud)