AWS Amplify Auth / Cognito 说得太多了?

Vic*_*ico 2 javascript amazon-web-services amazon-cognito aws-amplify

目前使用Cognito Javascript SDK,当我发送的用户名存在或不存在时,我有点惊讶地收到警告:

这是我正在使用的代码:

login(username, password) {
    const authenticationData = {
      Username : username,
      Password : password,
    };

    const authenticationDetails = new AuthenticationDetails(authenticationData);

    const userPool = new CognitoUserPool(this.poolData);
    const userData = {
      Username : username,
      Pool : userPool,
    };

    this.cognitoUser = new CognitoUser(userData);
    this.cognitoUser.authenticateUser(authenticationDetails, {
      onSuccess: function (result) {
        console.log(result);
      },
      newPasswordRequired: function(...) {

      },
      onFailure: function(err) {
        console.log(err);
      },
    });
  }
Run Code Online (Sandbox Code Playgroud)

如果我设置usernamemytest(现有用户)并使用错误的密码,则会收到以下错误:

“NotAuthorizedException” 用户名或密码不正确。

没关系。但如果我设置usernametest12345(非现有用户),我会收到此错误:

“UserNotFoundException” 用户不存在。

我认为告诉最终用户用户名是否存在并不真正安全。

我错了吗?难道是我做错了什么?

我只想让第一个例外通知最终用户登录失败。

小智 5

我花了一些时间才找到它,但在用户池客户端设置中有一个选项“防止用户存在错误”(常规设置 -> 应用程序客户端)。请参阅https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-managing-errors.html