繁体   English   中英

如何基于 cognito 用户池组角色访问 AWS APIGateway

[英]How to access the AWS APIGateway based on the cognito user pool group roles

我创建了一个用户池并添加了 2 个用户组。 注册 2 个用户并附加到不同的组。 The groups having different roles, 1 role having a policy, that can execute the Lambda function with resource GET /countries another role having another policy, that can execute the Lambda function with the resource POST /countries . 但是两个用户都可以通过将 ID 令牌作为授权 header 传递来访问这两个资源。

我使用了类似的政策

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "VisualEditor0",
        "Effect": "Allow",
        "Action": "execute-api:Invoke",
        "Resource": "arn:aws:execute-api:us-west-1:12098989898:sdsds56ffdf/*/GET/countries"
    }]
}

我需要在保单中添加任何条件吗? 为什么用户可以访问这 2 个资源。 我们如何根据用户池组进行限制?

您使用的默认认知授权方仅检查令牌是否有效并且是否属于正确的用户池。 如果您还想检查组,您可以使用自定义 lambda 授权器,使用 sdk 将令牌传递给 cognito 并检查用户所属的组。

或者您可以稍微更改授权人,使其将组名发送到您可以进行条件检查的后端。

https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM