【问题标题】:How to prevent access to certain fields in Amplify graphql public API如何防止访问 Amplify graphql 公共 API 中的某些字段
【发布时间】:2020-12-10 06:15:48
【问题描述】:

我在 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 密钥进行读取访问,但“作者”字段除外。它应该只能由所有者和“管理员”组读取。 我已经尝试过各种顶级和字段级@auth 指令的组合,但它不起作用。 有谁知道如何解决这个问题。 谢谢

【问题讨论】:

  • 我也有类似的问题.. 你在哪里可以弄清楚如何做到这一点?

标签: graphql authorization aws-amplify


【解决方案1】:

您是否尝试过使用Field Level Authorization?

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-21
    • 2020-01-05
    • 1970-01-01
    • 2017-11-05
    • 2016-08-11
    • 1970-01-01
    • 2021-02-19
    • 2015-01-19
    相关资源
    最近更新 更多