首页 > 解决方案 > firestore rest api 批量写入权限被拒绝

问题描述

我已禁用我的安全规则,因此任何人都可以更新、写入、创建、读取、删除allow read, write, delete, update, create;

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write, delete, update, create;
    }
  }
}

当我尝试使用`POST https://firestore.googleapis.com/v1/{database=projects/*/databases/*}/documents:batchWrite

身体如下

{
  "writes": [
    {
      "update": {
        "name": "projects/project_id/databases/(default)/documents/service_order/352003090342435.5f357270173e8c70878.-9486573",
        "fields": {
          "managed_by": {
            "booleanValue": "false"
          },
          "location2": {
            "booleanValue": "false"
          },
          "made_by": {
            "stringValue": "352003090342435.5eda4f3c17284c58460.90921842"
          },
          "phone2": {
            "stringValue": "0665439307"
          },
          "state": {
            "stringValue": "confirm"
          },
          "write_date": {
            "stringValue": "1597664391000"
          },
          "made_by_name": {
            "stringValue": "FaridBenabdallah"
          },
          "description": {
            "stringValue": "e1"
          },
          "accepted_offer": {
            "booleanValue": "false"
          },
          "id": {
            "stringValue": "352003090342435.5f357270173e8c70878.-9486573"
          },
          "location1": {
            "stringValue": "352003090342435.5f3572a0173e8c7c336.-8281409"
          },
          "date_order": {
            "booleanValue": "false"
          },
          "order_type": {
            "stringValue": "Minuiserie"
          },
          "phone1": {
            "stringValue": "0657331995"
          }
        }
      },
      "updateMask": {
        "fieldPaths": [
          "managed_by",
          "location2",
          "made_by",
          "phone2",
          "state",
          "write_date",
          "made_by_name",
          "description",
          "accepted_offer",
          "id",
          "location1",
          "date_order",
          "order_type",
          "phone1"
        ]
      }
    }
  ]
}

` rest api 它总是在拒绝许可的情况下响应

{
  "error": {
    "code": 403,
    "message": "Missing or insufficient permissions.",
    "status": "PERMISSION_DENIED"
  }
}

但是,当我使用 Google OAuth 2.0 尝试它时,它正在工作

所以当我不使用它时,batchWrite 有问题authoirzation header

标签: firebasegoogle-cloud-firestorefirebase-security

解决方案


支持人员回应说,火力基地内部似乎有问题

在我自己执行了一些额外的测试之后,看起来这种行为可能与 REST API 隔离,因为我们的 SDK 似乎都没有受到影响。我将继续与我们的工程师一起提出此行为,以查看这是否是预期行为,或者是否可能只是原始 REST 调用中缺少某些内容。一旦我有任何更新要分享,我会确保尽快与您联系。

所以我做了一些研究,发现我可以使用commit rest api,因为它看起来一样但是没有 authoirzation 标头或使用 firebase 令牌作为授权标头


推荐阅读