1

我想在我的应用程序中集成 Cognito 令牌。

我如何在 AWS Sam 模板中做到这一点?要更新我的模板,我查看https://docs.aws.amazon.com/fr_fr/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html?shortFooter=true

信息:

  • 我的 UserPool 是在 AWS 控制台中创建的(在 Web 上)
  • 我用没有标题的邮递员进行测试:如果它有效,我应该被拒绝 ==> 现实:我有结果(我的授权人不起作用)

==========================

我的问题是:为什么 Authorizer 不起作用?

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Globals:
  Function:
    Runtime: nodejs6.10
    Handler: index.handler
    Timeout: 30
Resources:
  GRApi:
    Type: 'AWS::Serverless::Api'
    Properties:
      Name: 'Myname'
      StageName: !Ref Stage
      Cors: "'*'"
      EndpointConfiguration: REGIONAL
      DefinitionBody:
        swagger: "2.0"
        info:
          version: "1.0"
          title: "myTitle"
          host: !Ref Host
        securityDefinitions:
          cognitoUserPool:
            type: apiKey
            name: Authorization
            in: header
            x-amazon-apigateway-authtype: cognito_user_pools
            x-amazon-apigateway-authorizer:
              type: cognito_user_pools
              providerARNs: 
                - "arn:aws:cognito-idp..."
        schemes:
          - "https"
        consumes:
          - application/json
        produces:
          - application/json
        paths:
          /project:
            get:
              responses: {}
              security:
                - cognitoUserPool: []
              x-amazon-apigateway-integration:
                uri:
                  - 'arn:aws:apigateway:....Arn'
                passthroughBehavior: "when_no_match"
                httpMethod: "POST"
                type: "aws_proxy"

GetAllProjectsFunction:
  Type: 'AWS::Serverless::Function'
  Properties:
    CodeUri: URI/
    Handler: index.handler
    Runtime: nodejs8.10
    MemorySize: 128
    Timeout: 30
    Role: 'arn:....role'
    Events:
    GetAllProjects:
      Type: Api
      Properties:
        Path: /project
        Method: get
        RestApiId: !Ref GRApi
Outputs: 
   ...
4

0 回答 0