Quản lý Quy tắc bảo mật cơ sở dữ liệu theo thời gian thực của Firebase thông qua REST
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tài liệu này giải thích cách bạn có thể quản lý Firebase Realtime Database Security Rules của ứng dụng thông qua REST API.
Đang cập nhật Firebase Realtime Database Security Rules
Bằng cách sử dụng REST API, bạn có thể ghi và cập nhật Firebase Realtime Database Security Rules cho ứng dụng Firebase của mình bằng cách đưa ra yêu cầu PUT đến đường dẫn /.settings/rules.json.
Để làm được việc này, chúng ta cần mã truy cập để xác thực yêu cầu REST
Trong ví dụ này, chúng ta bật quyền đọc cho tất cả dữ liệu trong cơ sở dữ liệu Firebase:
Đang truy xuất Firebase Realtime Database Security Rules
Tương tự, chúng ta có thể gửi yêu cầu GET đến đường dẫn /.settings/rules.json trong URL của ứng dụng để truy xuất Firebase Realtime Database Security Rules:
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[],[],null,["\u003cbr /\u003e\n\nThis document explains how you can manage your app's Firebase Realtime Database Security Rules through the REST API. \n\nUpdating Firebase Realtime Database Security Rules\n\n\nUsing the REST API, you can write and update\n[Firebase Realtime Database Security Rules](/docs/database/security) for your\nFirebase app by making a `PUT` request to the `/.settings/rules.json` path.\nTo do this, we'll need an access token to [authenticate our REST request](/docs/database/rest/auth)\n\n\nIn this example, we enable read access for all data in our Firebase database: \n\n```\ncurl -X PUT -d '{ \"rules\": { \".read\": true } }' 'https://docs-examples.firebaseio.com/.settings/rules.json?access_token=\u003cACCESS_TOKEN\u003e'\n```\nWriting Firebase Realtime Database Security Rules through the REST API will overwrite any existing rules. \n\nRetrieving Firebase Realtime Database Security Rules\n\n\nSimilarly, we can make a GET request to the `/.settings/rules.json` path of our app's\nURL to retrieve our Firebase Realtime Database Security Rules: \n\n```\ncurl 'https://docs-examples.firebaseio.com/.settings/rules.json?access_token=\u003cACCESS_TOKEN\u003e'\n```\n\n\nThe response will contain all of the rules for our app."]]