在AWS Unauthorized 401中测试GraphQL,授权程序存在问题

问题描述

使用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的令牌,我将其作为“承载令牌”使用,但仍然失败。有什么建议吗?

解决方法

您需要先调用Cognito以获得JWT令牌,然后将此令牌作为Bearer传递到请求Authorization标头中。我没有使用此路由,但是有一个API可以做到这一点:InitiateAuth