@@ -216,29 +216,59 @@ def _create_composite_credentials(
216216 )
217217
218218 if credentials_file :
219- credentials , _ = google .auth .load_credentials_from_file (
220- credentials_file ,
221- scopes = scopes ,
222- default_scopes = default_scopes
223- )
219+ try :
220+ credentials , _ = google .auth .load_credentials_from_file (
221+ credentials_file ,
222+ scopes = scopes ,
223+ default_scopes = default_scopes
224+ )
225+ # google-auth < x.x.x does not have `default_scopes`
226+ # TODO: remove this try/except once google-auth >= x.x.x is required
227+ except TypeError :
228+ credentials , _ = google .auth .load_credentials_from_file (
229+ credentials_file ,
230+ scopes = scopes or default_scopes ,
231+ )
224232 elif credentials :
225- credentials = google .auth .credentials .with_scopes_if_required (
226- credentials ,
227- scopes = scopes ,
228- default_scopes = default_scopes
229- )
233+ try :
234+ credentials = google .auth .credentials .with_scopes_if_required (
235+ credentials ,
236+ scopes = scopes ,
237+ default_scopes = default_scopes
238+ )
239+ # google-auth < x.x.x does not have `default_scopes`
240+ # TODO: remove this try/except once google-auth >= x.x.x is required
241+ except TypeError :
242+ credentials = google .auth .credentials .with_scopes_if_required (
243+ credentials ,
244+ scopes = scopes or default_scopes ,
245+ )
246+
230247 else :
231- credentials , _ = google .auth .default (scopes = scopes , default_scopes = default_scopes )
248+ try :
249+ credentials , _ = google .auth .default (scopes = scopes , default_scopes = default_scopes )
250+ # google-auth < x.x.x does not have `default_scopes`
251+ # TODO: remove this try/except once google-auth >= x.x.x is required
252+ except TypeError :
253+ credentials , _ = google .auth .default (scopes = scopes or default_scopes )
232254
233255 if quota_project_id and isinstance (credentials , google .auth .credentials .CredentialsWithQuotaProject ):
234256 credentials = credentials .with_quota_project (quota_project_id )
235257
236258 request = google .auth .transport .requests .Request ()
237259
238260 # Create the metadata plugin for inserting the authorization header.
239- metadata_plugin = google .auth .transport .grpc .AuthMetadataPlugin (
240- credentials , request , default_host = default_host ,
241- )
261+
262+ # google-auth < x.x.x does not have `default_host`
263+ # TODO: remove this try/except once google-auth >= x.x.x is required
264+ try :
265+ metadata_plugin = google .auth .transport .grpc .AuthMetadataPlugin (
266+ credentials , request , default_host = default_host ,
267+ )
268+ except :
269+ metadata_plugin = google .auth .transport .grpc .AuthMetadataPlugin (
270+ credentials , request
271+ )
242272
243273 # Create a set of grpc.CallCredentials using the metadata plugin.
244274 google_auth_credentials = grpc .metadata_call_credentials (metadata_plugin )
0 commit comments