graphql - 如何防止访问 Amplify graphql 公共(public) API 中的某些字段

标签 graphql authorization aws-amplify

我在 Amplify 中有一个 graphql 模型,如下所示:

type Blog @model @auth(rules: [
    { allow: owner },
    { allow: groups, groups: ["admins"] },
    { allow: public, provider: apiKey, operations: [read] }
    ]){
    id: ID!
    title: String!
    content: String!
    author: String
}

我希望所有字段都可以通过 API key 进行读取访问,除了“作者”字段。它应该只能由所有者和“管理员”组读取。 我已经尝试了顶级和字段级 @auth 指令的各种组合,但它不起作用。 有谁知道如何解决这个问题。 谢谢

最佳答案

您是否尝试过使用 Field Level Authorization

type User @model {
  id: ID!
  username: String
  ssn: String @auth(rules: [{ allow: owner, ownerField: "username" }])
}

更新:我的错误,在你的问题中它确实说你试过了。

关于graphql - 如何防止访问 Amplify graphql 公共(public) API 中的某些字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63513047/

相关文章:

ruby-on-rails - 未定义的方法 `admin?' 为 nil :NilClass

reactjs - 如何使用 aws cognito 联合身份处理重定向

javascript - GraphQL 参数如何与字段关联?

graphql - apollo graphql 模式 react-admin 初学者

python - 如何在python的graphql查询中修复 'parse error on (VAR_SIGN)'

javascript - 异步调用不评估 react 中的条件

react-native - 无法解析模块@react-native-async-storage/async-storage

domain-driven-design - 我可以使用不同的数据库作为 Wolkenkit 读取模型吗?

ios - 在移动应用程序内浏览器中打开时,iOS 中的魔术链接问题

asp.net - 当客户端cookie滑动时刷新IdentityServer cookie