한 권한을 거부에서 중포 기지를 사용하여 컬 및 자바스크립트
-
21-12-2019 - |
문제
나는 중포 기지와 보안 config 다음과 같다:
{
"rules": {
"serviceproviders": {
".read": "auth != null",
".write": "auth != null"
},
"bookings": {
".read": "auth != null",
".write": true,
".validate": "newData.hasChildren(['phone', 'time', 'date', 'apikey'])",
"apikey": {
// only allow valid apikey
".validate": "root.child('serviceproviders/' + newData.val()).exists()"
}
},
"status": {
".read": "auth != null",
".write": true
}
}
}
아이디어는 사용자가 게시물 /bookings/
유효한 apikey
, 즉 apikey
에서 찾을 수 있습니다 /serviceproviders/
.
에서 중포 기지 시뮬레이터,이 예상대로 작동합니다.그러나 내가 사용하는 경우 curl
터미널에서,또는 자바스크립트에서는 html 페이지,나 error: permission denied
에서 중포 기지.나는 정확하게 보낼 같은 데이터(복사&붙여 넣기).
나 curl
명령은 다음과 같습니다:
$ curl -X POST -d '{"phone":"004512345678", "date":"2014-07-31","time":"10:00","apikey":"AA227D80-122C-4E5D-AEDF-24A829FA6403"}' https://example.firebaseIO.com/bookings/.json
고 다시 얻을:
{
"error" : "Permission denied"
}
해결책
확인 후,그래서 많은 시간의 당신의 머리를 깨달았다는 가이드에에 Firebase.com 이, ".validate"
규칙은 내부 블록을 나타내는 ID 가는 경로,따라서:
{
"rules": {
"serviceproviders": {
".read": "auth != null",
".write": "auth != null"
},
"bookings": {
".read": "auth != null",
".write": true,
"$bookings_id": {
"apikey": {
// only allow valid apikey
".validate": "root.child('serviceproviders/' + newData.val()).exists()"
},
".validate": "newData.hasChildren(['apikey','date','time','phone'])"
}
},
"status": {
".read": "auth != null",
".write": true
}
}
}
예상대로 작동하기 때문에,의 "$bookings_id"
니다.
제휴하지 않습니다 StackOverflow