【问题标题】:AWS Cognito USER_PASSWORD_AUTH "Initiate Auth method not supported."AWS Cognito USER_PASSWORD_AUTH “不支持启动身份验证方法。”
【发布时间】:2020-08-29 21:54:23
【问题描述】:

我正在尝试执行以下操作:

  AWSUtil.generateSecretHash('test@test.com', ClientId).then(SECRET_HASH => {
    return AWSUtil.Cognito.adminInitiateAuth({
      AuthFlow: 'USER_PASSWORD_AUTH',
      ClientId,
      UserPoolId: process.env.COGNITO_USER_POOL_ID,
      AuthParameters: {
        USERNAME: 'test@test.com',
        PASSWORD: 'lamepassword123',
        SECRET_HASH
      }
    }).promise();
  })
  .then(resp => {
    console.log(resp)
  });

除了"Initiate Auth method not supported.",它不会返回任何东西

根据docs,这应该可以工作。什么给了?

【问题讨论】:

    标签: amazon-web-services amazon-cognito


    【解决方案1】:

    我遇到了同样的问题 - 根据 example here 使用 AuthFlow ADMIN_NO_SRP_AUTH 而不是 USER_PASSWORD_AUTH 解决了这个问题。

    【讨论】:

    • 为基于服务器的身份验证启用登录 API (ADMIN_NO_SRP_AUTH)
    【解决方案2】:

    App Clients 部分下,您是否为您的用户池启用了框:

    [x] Enable username-password (non-SRP) flow for app-based authentication (USER_PASSWORD_AUTH)
    

    【讨论】:

    • 我在问题中解释了同样的问题。我已经检查了您提到的那个框,但仍然出现错误。还有其他建议吗?
    【解决方案3】:

    如果使用 Serverless 框架,ALLOW_USER_PASSWORD_AUTH 需要添加到 ExplicitAuthFlows 节点。

    Resources:
      CognitoUserPool:
        Type: AWS::Cognito::UserPool
        Properties:
          # Generate a name based on the stage
          UserPoolName: ${self:provider.stage}-user-pool
          # Set email as an alias
          UsernameAttributes:
            - email
          AutoVerifiedAttributes:
            - email
    
      CognitoUserPoolClient:
        Type: AWS::Cognito::UserPoolClient
        Properties:
          # Generate an app client name based on the stage
          ClientName: ${self:provider.stage}-user-pool-client
          UserPoolId:
            Ref: CognitoUserPool
          ExplicitAuthFlows:
            - ALLOW_ADMIN_USER_PASSWORD_AUTH # See also: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolclient.html
            - ALLOW_USER_PASSWORD_AUTH
            - ALLOW_REFRESH_TOKEN_AUTH
            - ALLOW_USER_SRP_AUTH
          GenerateSecret: false
    
    # Print out the Id of the User Pool that is created
    Outputs:
      UserPoolId:
        Value:
          Ref: CognitoUserPool
    
      UserPoolClientId:
        Value:
          Ref: CognitoUserPoolClient
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-01
      • 2017-05-31
      • 2018-01-29
      • 2014-11-07
      • 2016-06-25
      • 1970-01-01
      • 2021-02-05
      相关资源
      最近更新 更多