SAM模板:将Cognito用户池集成到APIgateway中-授权程序不起作用

时间:2018-12-21 10:44:11

标签: amazon-web-services amazon-cognito aws-sam-cli

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

我如何在AWS Sam模板中执行此操作? 要更新模板,请查看https://docs.aws.amazon.com/fr_fr/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html?shortFooter=true

信息:

  • 我的UserPool是在AWS控制台(在线)中创建的
  • 我用没有标题的Postman进行了测试:如果可以,我应该被拒绝==>真实性:我有结果(我的授权者不起作用)

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

我的问题是:为什么授权者不起作用?

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: 
   ...

0 个答案:

没有答案