feat: Support JSON in the GOOGLE_APPLICATION_CREDENTIALS env var
#635
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
googleapis/google-cloud-php#8617 marked
keyFileandkeyFilePathoptions as deprecated.In kreait/firebase-php, I currently read
GOOGLE_APPLICATION_CREDENTIALSand check if it includes a inline JSON string. If it does, I decode it and use it to set thekeyFileoption.This allows projects using the SDK to set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable without having to provide a "physical" file.With this I create, for example, a FirestoreClient with the
keyFileoption.If I remove the option and rely on the
credentialFetcheroption, as documented, it doesn't seem to be used.FirestoreClientuses ClientTrait::getKeyFile(), and when it doesn't find the deprecated options, it falls back toCredentialsLoader::fromEnv(), which requires theGOOGLE_APPLICATION_CREDENTIALSto be a string.While this change does solve my particular issue, the correct way might be to have ClientTrait::configureAuthentication() check for the
credentialFetcheroption before checking for thekeyFileoption…However, I wonder if it might make sense to allow inline JSON in the
GOOGLE_APPLICATION_CREDENTIALSin general.