3

我正在尝试制作用于登录的 API (Lambda 和 API 网关)并使用 OTP 进行无密码身份验证验证身份验证。目标是使用 Angular 和使用 Flutter 的移动应用程序制作前端,但 AWS Amplify 不支持 Flutter。因此,通过创建这些 API 来服务于我的目的。前端代码(Auth.signInAuth.sendCustomChallengeAnswer)效果很好,但使用相同的代码验证身份验证 API不起作用。分享我的代码。

登录接口:

await Auth.signIn(phone);

验证 Auth API:(从登录期间存储的 DynamoDB返回的 c['Session'] )

    let otp = body['otp'];
    const poolData = {
        UserPoolId: '------ pool id -------',
        ClientId: '------ client id -------'
    };
    const userPool = new CognitoUserPool(poolData);
    const userData = {
        Username: '+12014222656',
        Pool: userPool
    };
    this.cognitoUser1 = new CognitoUser(userData);
    this.cognitoUser1['Session'] = c['Session'];

    await Auth.sendCustomChallengeAnswer(this.cognitoUser1, otp);
    const tokenDetails = await Auth.currentSession()

    response = {
        'statusCode': 201,
        'body': JSON.stringify({
            message: 'Verification successful',
            body:tokenDetails
        })
    }

在调试前端Auth.signIn响应和 Lambda API Auth.signIn响应后,我调查了从前端登录时返回的额外“存储”对象,并在通过Auth.sendCustomChallengeAnswer发送之前附加到this.cognitoUser1上。请参阅下面的截图: 这是从前端成功验证 OTP 的原因吗?如果是这样,如何制作 API(使用 Lambda 和 API 网关)以及它存储此存储对象的位置。卡在这里。任何建议和帮助将不胜感激。回复截图

4

1 回答 1

0

您可以设置自己的存储:https ://docs.amplify.aws/lib/auth/manageusers/q/platform/js#managing-security-tokens

于 2021-01-18T22:26:28.353 回答