AWS API Gateway - using Access Token with Cognito User Pool authorizer?

前端 未结 3 994
南旧
南旧 2021-02-02 12:49

I am configuring an app with various frontends (mobile and web apps) and a single API backend, powered by Lambda and accessed via AWS API Gateway.

As I\'m planning to us

3条回答
  •  余生分开走
    2021-02-02 13:20

    For those looking for an answer and are not using OAuth and are deploying using Serverless framework:

    What worked for me to make APGW accept accessToken was to modify my serverless.yml file as follows:

    functions:
      my-function:
        handler: path to source file
        events:
          - http:
              path: my-function
              method: post
              cors: true
              authorizer:
                type: COGNITO_USER_POOLS
                scopes:
                  - YOUR SCOPE HERE <- THIS IS THE TRICK
                authorizerId:
                  Ref: ApiGatewayAuthorizer
    

    The value of the scope can be found by reading the contents of your accessToken (for by pasting the token into https://jwt.io/ debugger).

提交回复
热议问题