我不明白我的授权有什么问题。
我有一个 Hello 函数,它只返回一条简单的静态消息。如果我在没有设置“Authorizer”的情况下部署,它就可以工作。我已经在邮递员上进行了测试。当我尝试添加授权者时,问题就出现了。
我的 Cognito 已完全正常工作。在我的前端,我可以注册,然后登录,然后从此登录会话获取令牌。
当我去邮差测试时,我总是得到“未经授权”的答案。在 Postman 上,我测试了 GET 方法,在“标头”选项卡上,我添加了“授权”属性,并粘贴了我从登录会话中获得的令牌值。我还在一些地方推荐的前缀“bearer”的值字段上对此进行了测试。没有成功。
过去一周我一直在努力解决这个问题。请,任何帮助都将非常有用。
serverless.yml
provider:
name: aws
runtime: nodejs10.x
stage: dev
region: eu-west-1
environment:
MY_TABLE: ${self:custom.myStage}_${self:custom.settings.tb_items}
MY_STAGE: ${self:custom.myStage}
MY_DOMAIN: ${self:custom.myDomain}
iamRoleStatements:
- Effect: "Allow"
Action:
- "dynamodb:GetItem"
- "dynamodb:PutItem"
- "dynamodb:UpdateItem"
- "dynamodb:DeleteItem"
- "dynamodb:Scan"
Resource: "*"
functions:
hello:
handler: ${self:custom.pathFunc}/phraseOption.hello
events:
- http:
method: GET
path: hello
cors: true
integration: lambda-proxy
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
resources:
Resources:
CognitoUserPool:
Type: "AWS::Cognito::UserPool"
DeletionPolicy: Retain
Properties:
MfaConfiguration: OFF
UserPoolName: ${self:custom.myStage}_aePool …Run Code Online (Sandbox Code Playgroud) unauthorized amazon-cognito aws-lambda aws-api-gateway serverless-framework