我遵循此 AWS API Gateway 文档并使用cognito identity token
. 我在控制台中测试了我的 cognito id 令牌API Gateway
,它有效:它给了我正确的值,从令牌中正确检索 sub 和 email 值:
然后我将 Authorizor 添加到我的方法中:
但是当我现在测试我的方法时,当我从 API Gateway 中的测试表单(方法内部)发送它们时,所有请求仍然通过(提供或不提供身份令牌):
我本来希望得到“未经授权”或“拒绝访问”的响应,但我得到了 200。我还尝试将方法请求中的“需要 API 密钥”设置为 true 并需要 Autorization 标头,但即便如此,上面的请求也会通过状态 200:
我还添加了
"context" : {
"sub" : "$context.authorizer.claims.sub",
"email" : "$context.authorizer.claims.email"
}
到我的映射模板,所以完整的模板现在看起来像这样:
{
"TableName": "myUsersTable",
"Key": {
"id": {"S": "$input.params('id')"},
"username": {"S": "$input.params('id')"}
},
"context" : {
"sub" : "$context.authorizer.claims.sub",
"email" : "$context.authorizer.claims.email"
}
}
但是 sub 和 email 的日志总是空的(并且响应状态仍然是 200):
Tue Dec 29 10:35:46 UTC 2020 : Endpoint request body after transformations: {
"TableName": "myUsersTable",
"Key": {
"id": {"S": "testUser"},
"username": {"S": "testUser"}
},
"context" : {
"sub" : "",
"email" : ""
}
}
我在这里做错了什么?