Skip to content

FirestoreOptions .setCredentials() seems to be ignored #3458

Closed
@andrewparmet

Description

@andrewparmet

I recently upgraded Firestore from version 0.51.0-beta to 0.52.0-beta, which allows overriding of various options. My instantiation broke and now throws this exception:
com.google.cloud.firestore.FirestoreException: java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

My previous service instantiation code looked like this:

GoogleCredentials creds = getServiceAccountCredentialsFromFile();
Firestore firestore = new DefaultFirestoreFactory()
    .create(
        FirestoreOptions.newBuilder()
            .setCredentials(creds)
            .setProjectId(projectId)
            .build());

After upgrading this config no longer works; I have to do something like this:

Firestore firestore = new DefaultFirestoreFactory()
    .create(
        FirestoreOptions.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(creds))
            .setProjectId(projectId)
            .build());

I have also tried this:

Firestore firestore = new DefaultFirestoreFactory()
    .create(
        FirestoreOptions.newBuilder()
            .setCredentials(creds)
            .setProjectId(config.getString("firestore.projectId"))
            .setCredentialsProvider(FirestoreOptions.getDefaultCredentialsProviderBuilder().build())
            .build());

but this also did not work.

Is it expected that setCredentials() is effectively ignored?

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the Firestore API.authpriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions