gpt4 book ai didi

amazon-dynamodb - AppSync 中使用 IAM 身份验证的组授权

转载 作者:行者123 更新时间:2023-12-04 16:04:49 25 4
gpt4 key购买 nike

我的服务需要用户组来授权访问数据。

AppSync 文档中的组授权示例基于用户池声明。我正在使用 IAM 身份验证,因此 $context.identity 不包含声明或任何类似信息。

例如,请参阅以下主题中的“用例:组可以创建新记录”:
https://docs.aws.amazon.com/appsync/latest/devguide/security-authorization-use-cases.html

#set($expression = "")
#set($expressionValues = {})
#foreach($group in $context.identity.claims.get("cognito:groups"))
#set( $expression = "${expression} contains(groupsCanAccess, :var$foreach.count )" )
#set( $val = {})
#set( $test = $val.put("S", $group))
#set( $values = $expressionValues.put(":var$foreach.count", $val))
#if ( $foreach.hasNext )
#set( $expression = "${expression} OR" )
#end
#end
{
"version" : "2017-02-28",
"operation" : "PutItem",
"key" : {
## If your table's hash key is not named 'id', update it here. **
"id" : { "S" : "$context.arguments.id" }
## If your table has a sort key, add it as an item here. **
},
"attributeValues" : {
## Add an item for each field you would like to store to Amazon DynamoDB. **
"title" : { "S" : "${context.arguments.title}" },
"content": { "S" : "${context.arguments.content}" },
"owner": {"S": "${context.identity.username}" }
},
"condition" : {
"expression": "attribute_not_exists(id) OR $expression",
"expressionValues": $utils.toJson($expressionValues)
}
}

我希望只从 User 表中检查用户是否在授予此权限的组中。但是,DynamoDB 条件似乎不支持查询其他表。

最佳答案

今天我正在使用类似于您的要求的东西。为此,我使用来自 Cognito 用户池的 JWT token 在放大请求中添加了一个自定义 header 。就我而言,我在 lambda 解析器中解析 JWT。对于您的情况,您需要在前端解析 JWT token 并将其发送到自定义 header 中解析(和编码)。在解析器中,您可以解码 header 值并从声明中提取组。

关于amazon-dynamodb - AppSync 中使用 IAM 身份验证的组授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49901500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com