def _get_application_default_credential_from_file(filename):
 from oauth2client import service_account
 with open(filename) as file_obj:
  client_credentials = json.load(file_obj)
 credentials_type = client_credentials.get('type')
 if (credentials_type == AUTHORIZED_USER):
  required_fields = set(['client_id', 'client_secret', 'refresh_token'])
 elif (credentials_type == SERVICE_ACCOUNT):
  required_fields = set(['client_id', 'client_email', 'private_key_id', 'private_key'])
 else:
  raise ApplicationDefaultCredentialsError((((("'type' field should be defined (and have one of the '" + AUTHORIZED_USER) + "' or '") + SERVICE_ACCOUNT) + "' values)"))
 missing_fields = required_fields.difference(client_credentials.keys())
 if missing_fields:
  _raise_exception_for_missing_fields(missing_fields)
 if (client_credentials['type'] == AUTHORIZED_USER):
  return GoogleCredentials(access_token=None, client_id=client_credentials['client_id'], client_secret=client_credentials['client_secret'], refresh_token=client_credentials['refresh_token'], token_expiry=None, token_uri=GOOGLE_TOKEN_URI, user_agent='Python client library')
 else:
  return service_account._ServiceAccountCredentials(service_account_id=client_credentials['client_id'], service_account_email=client_credentials['client_email'], private_key_id=client_credentials['private_key_id'], private_key_pkcs8_text=client_credentials['private_key'], scopes=[])

def _get_application_default_credential_from_file ( filename ) : from oauth2client import service_account with open ( filename ) as file_obj : client_credentials = json . load ( file_obj ) credentials_type = client_credentials . get ( 'type' ) if ( credentials_type == AUTHORIZED_USER ) : required_fields = set ( [ 'client_id' , 'client_secret' , 'refresh_token' ] ) elif ( credentials_type == SERVICE_ACCOUNT ) : required_fields = set ( [ 'client_id' , 'client_email' , 'private_key_id' , 'private_key' ] ) else : raise ApplicationDefaultCredentialsError ( ( ( ( ( "'type' field should be defined (and have one of the '" + AUTHORIZED_USER ) + "' or '" ) + SERVICE_ACCOUNT ) + "' values)" ) ) missing_fields = required_fields . difference ( client_credentials . keys ( ) ) if missing_fields : _raise_exception_for_missing_fields ( missing_fields ) if ( client_credentials [ 'type' ] == AUTHORIZED_USER ) : return GoogleCredentials ( access_token = None , client_id = client_credentials [ 'client_id' ] , client_secret = client_credentials [ 'client_secret' ] , refresh_token = client_credentials [ 'refresh_token' ] , token_expiry = None , token_uri = GOOGLE_TOKEN_URI , user_agent = 'Python client library' ) else : return service_account . _ServiceAccountCredentials ( service_account_id = client_credentials [ 'client_id' ] , service_account_email = client_credentials [ 'client_email' ] , private_key_id = client_credentials [ 'private_key_id' ] , private_key_pkcs8_text = client_credentials [ 'private_key' ] , scopes = [ ] )
build the application default credentials from file .