code: def _load_credentials_from_file(
      filename: str, target_audience: str | None
  ) -> google_auth_credentials.Credentials | None:
      """
      Loads credentials from a file.
  
      The credentials file must be a service account key or a stored authorized user credential.
  
      :param filename: The full path to the credentials file.
      :return: Loaded credentials
      :raise google.auth.exceptions.DefaultCredentialsError: if the file is in the wrong format or is missing.
      """
      if not os.path.exists(filename):
          raise exceptions.DefaultCredentialsError(
              f"File {filename} was not found."
          )
  
      with open(filename) as file_obj:
          try:
              info = json.load(file_obj)
          except json.JSONDecodeError:
              raise exceptions.DefaultCredentialsError(
                  f"File {filename} is not a valid json file."
              )
  
      # The type key should indicate that the file is either a service account
      # credentials file or an authorized user credentials file.
      credential_type = info.get("type")
  
      if credential_type == _AUTHORIZED_USER_TYPE:
          current_credentials = (
              oauth2_credentials.Credentials.from_authorized_user_info(
                  info, scopes=["openid", "email"]
              )
          )
          current_credentials = IDTokenCredentialsAdapter(
              credentials=current_credentials
          )
  
          return current_credentials
  
      elif credential_type == _SERVICE_ACCOUNT_TYPE:
          try:
              return service_account.IDTokenCredentials.from_service_account_info(
                  info, target_audience=target_audience
              )
          except ValueError:
              raise exceptions.DefaultCredentialsError(
                  f"Failed to load service account credentials from {filename}"
              )
  
      raise exceptions.DefaultCredentialsError(
          f"The file {filename} does not have a valid type. Type is {credential_type}, "
          f"expected one of {_VALID_TYPES}."
      )
  
file_path: airflow/airflow/providers/google/common/utils/id_token_credentials.py
imports: from __future__ import annotations
  import json
  import os
  from typing import TYPE_CHECKING
  import google.auth.transport
  from google.auth import credentials, environment_vars, exceptions
  from google.oauth2 import credentials, service_account
label_desc: Use image node_id 1 for calling a global function with example usage: _load_credentials_from_file(filename, target_audience) and returns: current_credentials, service_account