【问题标题】:Cognito - adminRespondToAuthChallenge returns Invalid session for the userCognito - adminRespondToAuthChallenge 为用户返回无效会话
【发布时间】:2021-03-28 12:23:40
【问题描述】:

第 1 步:我创建了一个客户,然后通过 adminInitiateAuth() 发起了一个授权挑战,这会触发 Cognito 中的 Create_auth_challenge。

第 2 步:用户收到一个 OTP,该 OTP 通过 adminRespondToAuthChallenge() 返回给 Cognito。

第 3 步:第一次一切正常。下面的示例请求/响应

{
    "username": "bf2e77f6-c5ec-4644-8f52-2076fa1d4e5a",
    "answer": "1725",
    "session": "xxxxxxxx..."
}

响应示例:

{
    "ChallengeParameters": {},
    "AuthenticationResult": {
        "AccessToken": "xxxx..",
        "ExpiresIn": 3600,
        "TokenType": "Bearer",
        "RefreshToken": "ccccc...",
        "IdToken": "mmmm.."
    }
}

第 4 步:如果我从第 1 步重新开始,则第 2 步在接下来的 3 次中始终失败。

使用新会话 ID 发送到 adminRespondToAuthChallenge() 的请求。

{
    "username": "bf2e77f6-c5ec-4644-8f52-2076fa1d4e5a",
    "answer": "1725",
    "session": "xxxxxxxx..." 
}

回复:

{
    "message": "Invalid session for the user.",
    "code": "NotAuthorizedException",
    "time": "2020-12-17T19:06:05.449Z",
    "requestId": "dbe83978-25b4-4b6b-ac4a-696b1a16c71d",
    "statusCode": 400,
    "retryable": false,
    "retryDelay": 24.18704505654443
}

第 5 步:最后,第五次尝试再次正常工作。

无论每次尝试之间的延迟如何,这种行为都会表现出来。

你能帮我理解发生了什么吗?

【问题讨论】:

  • 嗨。你找到答案了吗?我也遇到了同样的问题。
  • 请看我下面的评论

标签: javascript node.js amazon-web-services aws-lambda amazon-cognito


【解决方案1】:

我删除了回调并使用了响应。 :) 希望这会有所帮助。

我更改了我的代码

const result = cognitoidentityserviceprovider.adminRespondToAuthChallenge(payload,
    async (err, data) => {
      if (err) {
        log.info('Init auth Response', {
          err
        });
        return err;
      } else {
        log.info('Init auth Response', {
          data
        });
        return data;
      }
    });

  const result = cognitoidentityserviceprovider.adminRespondToAuthChallenge(payload);
log.info('Init auth Response', {
    result
  });

【讨论】:

  • 谢谢拉米亚。是的。我也在做同样的事情。我删除了回调并且它起作用了。
猜你喜欢
  • 2022-11-01
  • 1970-01-01
  • 2018-12-22
  • 1970-01-01
  • 2019-06-26
  • 2012-03-14
  • 1970-01-01
  • 1970-01-01
  • 2018-12-04
相关资源
最近更新 更多