【问题标题】:Authenticate AppSync queries console with Cognito User Pools使用 Cognito 用户池对 AppSync 查询控制台进行身份验证
【发布时间】:2021-03-07 18:01:00
【问题描述】:

我正在尝试在 AWS AppSync 控制台中对 Queries Playground 进行身份验证。我创建了用户池并将其链接到 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。问题是我无法选择任何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

【问题讨论】:

  • 听起来像一个愚蠢的问题,但只是想排除这种可能性,你是如何将你的用户池链接到你的 GraphQL API 的?另外,API 和 User Pool 是否在同一个区域?
  • 根本不是一个愚蠢的问题,您回头查看 CloudFormation yaml 发现了问题

标签: amazon-cognito aws-appsync aws-userpools


【解决方案1】:

要使用 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 文件

【讨论】:

    猜你喜欢
    • 2020-09-30
    • 2018-02-23
    • 2021-04-08
    • 2021-06-23
    • 2016-08-18
    • 2021-04-12
    • 2018-11-06
    • 2017-12-03
    • 2019-09-30
    相关资源
    最近更新 更多