【问题标题】:How to setup Oauth scopes at AWS Serverless Function?如何在 AWS 无服务器函数中设置 Oauth 范围?
【发布时间】:2021-02-08 17:04:12
【问题描述】:

问题:OAuth 范围在使用 Cloudformation 和 AWS-SAM 的方法请求设置中为空

显然,我可以在一些地方声明我的授权范围,如果我做对了,我应该在授权方声明所有范围,以及我想在我的 Function 模板中为每个函数指定的范围。

这是我要修复的模板:

MyServerlessFn
 Type: AWS::Serverless::Function
    Properties:
      FunctionName: helloWorldFn
      Description: my test using cognito.
      Handler: src/handlers/helloWorld.handler
      Runtime: nodejs12.x
      Events:
        ApplicationPostAPI:
          Type: Api
          Properties:
            Auth:
              AuthorizationScopes:
                - https://foobar.acme.net/full-api
            Method: POST
            Path: /hello/world
            RestApiId: !Ref MyServerlessApi

使用 sam cli 我可以验证、构建和部署这个模板,但是当我使用 AWS Web 控制台检查它时,oauthScopes 是空的。

这里是 aws 文档: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-apifunctionauth.html

【问题讨论】:

    标签: amazon-cloudformation aws-serverless aws-sam aws-sam-cli


    【解决方案1】:

    我还注意到您在函数级别定义的范围保持为空。 无论是文档错误还是当前的 AWS SAM 错误,我都留在了中间。 (见:https://github.com/aws/serverless-application-model/issues/1752

    但是,您可以通过在 api 级别指定授权方并在函数级别引用此授权方来解决此问题。

      ApiGw:
        Type: AWS::Serverless::Api
        Properties:
          Description: some description
          Auth:
            Authorizers:
              DefaultAuthorizer:
                UserPoolArn: somepool
                AuthType: "COGNITO_USER_POOLS"
              AuthorizerWithScopeABC:
                UserPoolArn: somepool
                AuthType: "COGNITO_USER_POOLS"
                AuthorizationScopes:
                  - /ABC
              AuthorizerWithScopeXYZ:
                UserPoolArn: somepool
                AuthType: "COGNITO_USER_POOLS"
                AuthorizationScopes:
                  - /XYZ
            DefaultAuthorizer: DefaultAuthorizer
    
      Function:
        Type: AWS::Serverless::Function
        Properties:
          Events:
            ApiEvent:
              Type: Api
              Properties:
                Path: /somepath
                Method: get
                RestApiId: !Ref ApiGw
                Auth:
                  Authorizer: AuthorizerWithScopeABC
    

    【讨论】:

      猜你喜欢
      • 2015-11-03
      • 2018-11-24
      • 1970-01-01
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      • 2015-12-03
      相关资源
      最近更新 更多