使用 Cognito 用户池对 AppSync 查询控制台进行身份验证

Authenticate AppSync queries console with Cognito User Pools

我正在尝试在 AWS AppSync 控制台中对查询游乐场进行身份验证。我已经创建了用户池并将其链接到 AppSync API,我还在 Cognito 用户池中创建了一个应用程序客户端(使用 CloudFormation 部署)。它出现在控制台的 Select the authorization provider to use for running queries on this page: 下。 当我 运行 测试查询时,我得到:

{
  "errors": [
    {
      "errorType": "UnauthorizedException",
      "message": "Unable to parse JWT token."
    }
  ]
}

这是我所期望的。有一个选项Login with User Pools。问题是我不能 select 任何 Client ID,当我选择手动插入客户端 ID 时,我输入的任何内容都会得到 Invalid UserPoolId format。我正在尝试从用户池常规设置(格式 eu-west-2_xxxxxxxxx)复制池 ID,但没有成功。顺便说一句,我没有使用 Amplify,也没有配置任何身份池。

编辑:

这里是 CloudFormation GraphQLApi 定义:

  MyApi:
    Type: AWS::AppSync::GraphQLApi
    Properties:
      Name: !Sub "${AWS::StackName}-api"
      AuthenticationType: AMAZON_COGNITO_USER_POOLS
      UserPoolConfig:
        UserPoolId: !Ref UserPoolClient
        AwsRegion: !Sub ${AWS::Region}
        DefaultAction: ALLOW

为了使用 CloudFormation 设置堆栈,我遵循了以下 2 个示例:

https://adrianhall.github.io/cloud/2018/04/17/deploy-an-aws-appsync-graphql-api-with-cloudformation/

https://gist.github.com/adrianhall/f330a10451f05a529680f32978dddb64

结果他们(同一作者)在定义 ApiGraphQL 的部分中都有问题。这个:

  MyApi:
    Type: AWS::AppSync::GraphQLApi
    Properties:
      Name: !Sub "${AWS::StackName}-api"
      AuthenticationType: AMAZON_COGNITO_USER_POOLS
      UserPoolConfig:
        UserPoolId: !Ref UserPoolClient
        AwsRegion: !Sub ${AWS::Region}
        DefaultAction: ALLOW

应该是:

  MyApi:
    Type: AWS::AppSync::GraphQLApi
    Properties:
      Name: !Sub "${AWS::StackName}-api"
      AuthenticationType: AMAZON_COGNITO_USER_POOLS
      UserPoolConfig:
        UserPoolId: !Ref UserPool
        AwsRegion: !Sub ${AWS::Region}
        DefaultAction: ALLOW

感谢@Myz 指点我回顾整个 CF yaml 文件