Firebase Cloud Firestore не работает во флаттере - PullRequest
0 голосов
/ 11 июля 2020

Я создаю это приложение, которое использует облачный хранилище пожаров. Проблема в том, что firestore не работает. Вот какой код я использую

Db.dart

class Db{

  // collection reference
  static final CollectionReference _collectionReference = Firestore.instance.collection("codes");

  static Future addOrUpdateCode(String code , double lat , double long) async {
    return await _collectionReference.document(code).setData({
      'lat':lat,
      'long':long
    });
  }

}

Я добавил эту строку в pubspe c .yaml

cloud_firestore: ^0.13.7

Я получаю эти ошибки

I/BiChannelGoogleApi(13145): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@b61eba8
W/Firestore(13145): (21.3.0) [FirestoreCallCredentials]: Failed to get token: com.google.firebase.FirebaseException: An internal error has occurred. [ yRequests to this API securetoken.googleapis.com method google.identity.securetoken.v1.SecureToken.GrantToken are blocked.�
W/Firestore(13145): #type.googleapis.com/google.rpc.Helpq
W/Firestore(13145): o
W/Firestore(13145):  Google developer console API keyKhttps://console.developers.google.com/project/280924879656/apiui/credential ].
I/BiChannelGoogleApi(13145): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@b61eba8
W/Firestore(13145): (21.3.0) [FirestoreCallCredentials]: Failed to get token: com.google.firebase.FirebaseException: An internal error has occurred. [ yRequests to this API securetoken.googleapis.com method google.identity.securetoken.v1.SecureToken.GrantToken are blocked.�
W/Firestore(13145): #type.googleapis.com/google.rpc.Helpq
W/Firestore(13145): o
W/Firestore(13145):  Google developer console API keyKhttps://console.developers.google.com/project/280924879656/apiui/credential ].
I/BiChannelGoogleApi(13145): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@b61eba8

В облачной консоли включены следующие API:

enter image description here

Register through email/password also enabled in firebase

I am using these rules

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

Я считаю, что этой информации достаточно. Спасибо за ваше время.

Ответы [ 2 ]

2 голосов
/ 12 июля 2020

Правила безопасности Firestore не настроены должным образом. См. Начало работы с правилами безопасности Cloud Firestore .

Поскольку вы упомянули, что реализуете аутентификацию Firebase, вам понадобится что-то вроде примера, который они предоставляют:

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}

Но обратите внимание, что вы, вероятно, также захотите иметь многоуровневое администрирование, которое осуществляется с помощью Custom Tokens . См. Create Custom Tokens , и вы, вероятно, получите что-то вроде правила, разрешающего доступ администратора ко всему, а затем вы сузите доступ оттуда, например:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.token.admin == true;
    }
    match /users/{userId} {
      allow read, write: if request.auth.uid == userId;
    }
  }
}
2 голосов
/ 11 июля 2020

Эти правила:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

запрещают доступ для чтения / записи всем пользователям при любых условиях. Вы должны изменить их на следующие:

// Allow read/write access to all users under any conditions
// Warning: **NEVER** use this rule set in production; it allows
// anyone to overwrite your entire database.
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

или использовать timestamp.date:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.time < timestamp.date(2020, 07, 28);
    }
  }
}

, что позволит читать и писать до указанного времени.

https://firebase.google.com/docs/firestore/security/get-started#allow -все

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...