Search code examples
androidfirebase-storagefirebase-security

Firebase authentication and google-service.json


I am new to Firebase. After reading Firebase doc, my understanding is that if I download google-service.json and drop it to Application folder of Android Studio project, the Firebase lib will do authentication under the hood so that I can access any of Firebase services storage, database etc.
I set Firebase Storage rule as allow only if client is authenticated
allow read, write: if request.auth != null;
But I am getting this error

User does not have permission to access this object.  

If I remove if request.auth != null part, it works fine.

Could anyone help me to understand what is google-service.json for?

If this json is not for authentication, what is recommended authentication?

Thanks in advance.


Solution

  • The configuration data in google-service.json allows your Android app to find its Firebase project on Google's servers.

    Given that the security rules are affecting whether your code works, it seems that your app can reach the project fine.

    So the problem is not in connecting the app to the project, but in your code that signs the user in. It's impossible to say what is wrong, since you didn't share the code, but you'll want to check if there is a currently signed in user just before calling the Storage API:

    if (FirebaseAuth.getInstance().getCurrentUser() != null) {
      ... call to Storage here
    }