Cognito Auth.sendCustomChallengeAnswer 给出“AuthClass - 无法获取登录用户没有当前用户”

Posted

技术标签:

【中文标题】Cognito Auth.sendCustomChallengeAnswer 给出“AuthClass - 无法获取登录用户没有当前用户”【英文标题】:Cognito Auth.sendCustomChallengeAnswer gives "AuthClass - Failed to get the signed in user No current user" 【发布时间】:2020-11-16 05:16:44 【问题描述】:

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

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

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于Cognito Auth.sendCustomChallengeAnswer 给出“AuthClass - 无法获取登录用户没有当前用户”的主要内容,如果未能解决你的问题,请参考以下文章

Flutter 和 Amplify/Cognito:如何使用 Flutter 更新 Amplify/cognito 中的电话号码

从 Cognito 收到 JWT Token 后如何存储?通过 Cognito 托管 UI 登录

如何使用Facebook验证使用Cognito的API调用?

无法在具有无服务器和 DynamoDB/Cognito/API 网关的 lambda 策略中使用 $cognito-identity.amazonaws.com:sub

text [使用CLI注册Cognito用户] #aws #cognito#aws-cli

AWS Cognito:Cognito 用户池的元数据 URL 在哪里?