FirestoreOptions not loading projectid from credentials correctly
See original GitHub issueI recently migrated from an older version (0.45) where I configured firestore using the FirebaseOptions, e.g.
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(_firebaseCredentialsPath));
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(credentials)
.build();
FirebaseApp.initializeApp(options);
_database = FirestoreClient.getFirestore();
This works. I migrated to the new way of doing things with FirestoreOptions (0.56.0). I got warnings to change the configuration. So the resulting code is now:
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(_firebaseCredentialsPath));
FirestoreOptions fireStoreOptions =
FirestoreOptions.newBuilder().setTimestampsInSnapshotsEnabled(true)
.setCredentials(credentials)
.build();
_database = fireStoreOptions.getService();
However, this code fails. It requires that the projectId field be set using .setProjectId(“…”). In my case it defaulted to another project in cloud that did not have firestore enabled. Perhaps the default project in cloud? It’s unclear. This seems like a bug. The project id is not available from the credentials API, even though it is there. Why is the projectid being ignored / not set from credentials correctly?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Firestore Server Authentication: Overlapping Documentation
Initialize on your own server To use the Firebase Admin SDK on your own server, use a service account. Go to IAM &...
Read more >The application default credentials are not available. They are ...
I have a project where i am calling Google Cloud Storage API from Firebase Cloud FireStore API. This is my Firebase code before...
Read more >FirestoreOptions (Google Cloud 0.98.0-alpha API)
Returns whether a service requires a project ID. This method may be overridden in service-specific Options objects. Overrides: projectIdRequired in class ...
Read more >firebase-admin.app package
Credential, Interface that provides Google OAuth2 access tokens used to authenticate with Firebase services.In most cases, you will not need to implement ...
Read more >Spring Cloud GCP
The project ID specified in the JSON credentials file pointed by the ... instead, let the Spring Cloud GCP Starter get the correct...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can confirm this, and that https://github.com/GoogleCloudPlatform/google-cloud-java/issues/3458 still is a problem. I’m using 0.56.0-beta.
For context:
val credentials = ServiceAccountCredentials.fromStream(stream)
loads credentials from a service account json file that is an owner in a project set aside for running tests.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
, nosetProjectId
:In other words, it’s looking in the wrong place.
setCredentialsProvider
with aFixedCredentialsProvider.create(credentials)
, withsetProjectId
: everything works.setCredentials(credentials)
, nosetProjectId
:setCredentials(credentials)
, withsetProjectId
:Which, I’m guessing, is it trying to use the default credentials on the test project’s Firestore, which of course won’t work. In other words, https://github.com/GoogleCloudPlatform/google-cloud-java/issues/3458. (Have I mentioned how much I dislike the concept of silent default credentials?)
For comparison, with 0.51.0-beta,
setCredentials(credentials)
, withsetProjectId
works fine.If I read this issue correctly, this seems like “working as intended”. The user / service account used by the application needs to have access to the project resources being accessed. In this case, it sounds like the permissions of the user being used didn’t align properly with the code.
There is an effort to move away from the implicit permissions, but that’s going to take some time. I don’t see anything actionable on this issue, at this point, so I’m closing it. Please feel free to open a different issue to address documentation related issues around credentials.