在 AWS Unauthorized 401 中测试 GraphQL,Authorizer 有问题

Test GraphQL in AWS Unauthorized 401, problem with Authorizer

使用 Serverless 我有这个配置:

functions:
  my-account:
    handler: src/index.handler
    events:
      - http:
          path: /my-account
          method: post
          cors: true
          authorizer:
            name: authorizer
            arn: arn:aws:cognito-idp:${self:provider.region}:XXXXXX:userpool/${self:custom.YYYY.cognito.userpool}

我正在尝试使用 Postman 进行测试,但我得到了一个:

{
    "message": "Unauthorized"
}

我没有得到它需要什么样的授权。我没有 API KEY,我在使用该 graphql 的应用程序中有一个令牌,我将其作为“Bearer Token”,但它仍然失败。有什么建议吗?

您需要先调用 Cognito 以获取 JWT 令牌,然后将其作为 Bearer 在请求授权 header 中传递。我没有使用过这条路线,但有一个 API 可以做到这一点:InitiateAuth