【问题标题】:AWS Amplify AppSync GraphQL @Auth directive: How can I forbid to list of elements for public userAWS Amplify AppSync GraphQL @Auth 指令:如何禁止为公共用户列出元素
【发布时间】:2021-11-22 01:39:57
【问题描述】:

我正在创建一个带有 Amplify 后端的 React 应用程序。到目前为止效果很好,但我想禁止某些用户可以列出一些元素。让我举一个graphql定义的例子:

type Customer @model 
@auth(rules: [
   {allow: public, , operations: [read,create,update]},
   {allow: groups, groups: ["admin","partner"] }])  
{
   id: ID!
   firstName: String
   lastName: String
   email: String
   phone: String
}

我们有未登录的客户,因此他们是公开的。他们知道他们的 id(因为它在他们创建客户条目之后的 url 中)并且他们应该能够更新、读取和创建他们自己的用户。那工作得很好。 不幸的是,他们还可以使用 listCustomers 查询。因此他们可以看到所有其他条目。我可以以某种方式禁止这个吗?据我了解,“读取”操作意味着“获取”和“列表”。

认知组也应该如此。 “admin”应该可以做所有事情,包括“list”和“partner”应该只能“get”。

有人有想法吗?我已阅读文档并在 Google 上搜索过,但似乎没有找到答案。

最好的问候

【问题讨论】:

    标签: amazon-web-services graphql authorization amplify


    【解决方案1】:

    回答我的问题:

    您可以为授权规则添加 {allow: public, queries: [get, list], mutation: [create,update]}。不幸的是,这已被弃用。不知道以后会不会有类似的东西。

    见:https://docs.amplify.aws/cli/graphql-transformer/auth/#definition

    type Customer @model @auth(rules: [
        { allow: public, queries: [get], mutations: [create,update]},
        { allow: groups, groups: ["admin"] },
        { allow: groups, groups: ["partner"], queries: [get],  mutations: []}])  
    {
    id: ID!
    firstName: String
    lastName: String
    email: String
    phone: String
    request: [Request] @connection(keyName: "byCustomer", fields: ["id"])
    }
    

    【讨论】:

      猜你喜欢
      • 2020-08-20
      • 2020-07-12
      • 2020-08-28
      • 2021-04-24
      • 2020-11-23
      • 2019-04-14
      • 2019-07-18
      • 2020-04-17
      • 2020-08-14
      相关资源
      最近更新 更多