1919
2020use Google \Auth \Credentials \GCECredentials ;
2121use Google \Auth \CredentialsLoader ;
22+ use Google \Auth \FetchAuthTokenInterface ;
23+ use Google \Auth \ProjectIdProviderInterface ;
2224use Google \Cloud \Core \Compute \Metadata ;
2325use Google \Cloud \Core \Exception \GoogleException ;
2426
@@ -93,7 +95,12 @@ private function getGrpcInstallationMessage()
9395 */
9496 private function configureAuthentication (array $ config )
9597 {
96- $ config ['keyFile ' ] = $ this ->getKeyFile ($ config );
98+ $ credentialsFetcher = $ config ['credentialsFetcher ' ] ?? null ;
99+
100+ if (!($ credentialsFetcher instanceof FetchAuthTokenInterface)) {
101+ $ config ['keyFile ' ] = $ this ->getKeyFile ($ config );
102+ }
103+
97104 $ this ->projectId = $ this ->detectProjectId ($ config );
98105
99106 return $ config ;
@@ -170,6 +177,7 @@ private function getKeyFile(array $config = [])
170177 private function detectProjectId (array $ config )
171178 {
172179 $ config += [
180+ 'credentialsFetcher ' => null ,
173181 'httpHandler ' => null ,
174182 'projectId ' => null ,
175183 'projectIdRequired ' => false ,
@@ -186,6 +194,10 @@ private function detectProjectId(array $config)
186194 return 'emulator-project ' ;
187195 }
188196
197+ if ($ config ['credentialsFetcher ' ] instanceof ProjectIdProviderInterface) {
198+ return $ config ['credentialsFetcher ' ]->getProjectId ();
199+ }
200+
189201 if (isset ($ config ['keyFile ' ])) {
190202 if (isset ($ config ['keyFile ' ]['project_id ' ])) {
191203 return $ config ['keyFile ' ]['project_id ' ];
0 commit comments