我想通過 REST API 從 Firestore 獲取資料。我正在使用 HTTP 客戶端 (Webstorm) 并執行以下操作。
首先,我使用 Google 進行身份驗證,它作業正常并回傳一個令牌:
POST https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=<firebase-api-key>
Accept: application/json
Content-Type: application/json
{
"email": "[email protected]",
"password": "notthispassword"
}
但是,然后,嘗試像這樣從 Firestore(不是實時資料庫)獲取資料
GET https://firestore.googleapis.com/v1/projects/<projectId>/databases/(default)/documents/<collection>
Accept: application/json
Authorization: Bearer <token from auth response>
它一直告訴我:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
這些是我的 Firestore 安全規則:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
如果有人能告訴我我哪里出錯了,我會很高興。
uj5u.com熱心網友回復:
解決方案的第一部分是仔細閱讀回復。它包含以下鏈接https://developers.google.com/identity/sign-in/web/devconsole-project。
然后我必須明白,如果您使用的是 google-identitiy-toolkit,那么您就離開了 firebase-realm 并且必須附加在 GC-console 中生成的 api-key(不是 firebase-key!)(https:// console.cloud.google.com/apis/credentials ) 到用于獲取資料的 URL,如下所示:
GET https://firestore.googleapis.com/v1/projects/<projectId>/databases/(default)/documents/<collection>?key=<google-cloud-api-key>
Accept: application/json
Authorization: Bearer <token from auth response>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/364315.html
標籤:休息 验证 谷歌云firestore
上一篇:Blazor導航管理器/身份驗證
