AWS使用GraphQL进行了扩展—定义不同类型用户的身份验证规则
使用Amplify、GraphQL、AppSync、Cognito、DynamoDB 具有以下型号:AWS使用GraphQL进行了扩展—定义不同类型用户的身份验证规则,graphql,amazon-dynamodb,amazon-cognito,aws-amplify,aws-appsync,Graphql,Amazon Dynamodb,Amazon Cognito,Aws Amplify,Aws Appsync,使用Amplify、GraphQL、AppSync、Cognito、DynamoDB 具有以下型号: type Post @model { id: ID! content: String! author: String! } 我希望我的规则能够启用以下情况: 只有管理员用户可以创建、更新和删除帖子 一些只有高级用户才允许阅读的帖子 所有登录用户都允许阅读的某些帖子 所有用户(也未经验证)允许阅读的某些帖子 使用上述工具实现它的最佳方式是什么 谢谢你的提问,现在还不清楚你如何定义“一
type Post
@model
{
id: ID!
content: String!
author: String!
}
我希望我的规则能够启用以下情况:
谢谢你的提问,现在还不清楚你如何定义“一些帖子”以及如何区分它们。如果我在设计这个,我会在我的
Post
类型中至少有一个字段来管理访问级别(例如:3(管理)>2(高级)>1(登录)>0(未注册)),就像这样
type Post
@model
{
id: ID!
content: String!
author: String!
accessLevel: Int!
}
要在用户级别上管理它,我认为最好的办法是使用Cognito组(如中提到的)来管理它,并为每个组分配适当的权限
您在Cognito中需要的东西:
type Mutation {
createPost(id:ID!, content:String!, author:String!):Post!
@aws_auth(cognito_groups: ["Admin"])
updatePost(id:ID!, content:String!, author:String!):Post!
@aws_auth(cognito_groups: ["Admin"])
deletePost(id:ID!, content:String!, author:String!):Post!
@aws_auth(cognito_groups: ["Admin"])
}
type Query {
getPost(id:ID!):Post!
@aws_api_key @aws_cognito_user_pools
}
此外,您可以使用解析器中的accessLevel
,根据您希望高级用户、登录用户或未注册用户看到的帖子筛选出结果
type Post
@model
@auth(
rules: [
{ allow: owner }
{ allow: groups, groups: ["Admin"], operations: [create, update, delete] }
{ allow: groups, groupsField: "group", operations: [read] }
]
) {
id: ID!
content: String!
author: String!
group: [String] # or String for a single group
}
您可以添加您正在使用的数据存储吗?你在用DynamoDB吗?还有,AppSync/GraphQL-Lambda背后是什么?完成您尝试的一种方法是:创建Cognito角色,并仅为不同用户的Lambda执行授予该角色权限。谢谢。我将编辑我的问题。我正在使用DynamoDB,还没有任何Lambda函数,但计划添加。非常感谢您的详细回答。第一部分对我帮助很大。我在上面分享了我的完整解决方案。我很想听听你对这件事的看法。。