diff --git a/google/auth/_default.py b/google/auth/_default.py
index f3e498b..694033f 100644
--- a/google/auth/_default.py
+++ b/google/auth/_default.py
@@ -116,11 +116,13 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
         try:
             credentials = credentials.Credentials.from_authorized_user_info(
                 info, scopes=scopes
-            ).with_quota_project(quota_project_id)
+            )
         except ValueError as caught_exc:
             msg = "Failed to load authorized user credentials from {}".format(filename)
             new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
             six.raise_from(new_exc, caught_exc)
+        if quota_project_id:
+            credentials = credentials.with_quota_project(quota_project_id)
         if not credentials.quota_project_id:
             _warn_about_problematic_credentials(credentials)
         return credentials, None
@@ -131,11 +133,13 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
         try:
             credentials = service_account.Credentials.from_service_account_info(
                 info, scopes=scopes
-            ).with_quota_project(quota_project_id)
+            )
         except ValueError as caught_exc:
             msg = "Failed to load service account credentials from {}".format(filename)
             new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
             six.raise_from(new_exc, caught_exc)
+        if quota_project_id:
+            credentials = credentials.with_quota_project(quota_project_id)
         return credentials, info.get("project_id")
 
     else:
@@ -317,9 +321,10 @@ def default(scopes=None, request=None, quota_project_id=None):
     for checker in checkers:
         credentials, project_id = checker()
         if credentials is not None:
-            credentials = with_scopes_if_required(
-                credentials, scopes
-            ).with_quota_project(quota_project_id)
+            credentials = with_scopes_if_required(credentials, scopes)
+            if quota_project_id:
+                credentials = credentials.with_quota_project(quota_project_id)
+
             effective_project_id = explicit_project_id or project_id
             if not effective_project_id:
                 _LOGGER.warning(

_default always sets `credentials.quota_project_id` to None
#546 introduced a bug where the quota project id always gets set to `None`. If no `quota_project_id` is passed to `load_credentials_from_file(...)` or `default(...)`, the existing project should not be overridden
diff --git a/tests/test__default.py b/tests/test__default.py
index 0665efa..55a14c2 100644
--- a/tests/test__default.py
+++ b/tests/test__default.py
@@ -165,6 +165,15 @@ def test_load_credentials_from_file_service_account_with_scopes():
     assert credentials.scopes == ["https://www.google.com/calendar/feeds"]
 
 
+def test_load_credentials_from_file_service_account_with_quota_project():
+    credentials, project_id = _default.load_credentials_from_file(
+        SERVICE_ACCOUNT_FILE, quota_project_id="project-foo"
+    )
+    assert isinstance(credentials, service_account.Credentials)
+    assert project_id == SERVICE_ACCOUNT_FILE_DATA["project_id"]
+    assert credentials.quota_project_id == "project-foo"
+
+
 def test_load_credentials_from_file_service_account_bad_format(tmpdir):
     filename = tmpdir.join("serivce_account_bad.json")
     filename.write(json.dumps({"type": "service_account"}))
@@ -465,6 +474,18 @@ def test_default_scoped(with_scopes, unused_get):
     with_scopes.assert_called_once_with(MOCK_CREDENTIALS, scopes)
 
 
+@mock.patch(
+    "google.auth._default._get_explicit_environ_credentials",
+    return_value=(MOCK_CREDENTIALS, mock.sentinel.project_id),
+    autospec=True,
+)
+def test_default_quota_project(with_quota_project):
+    credentials, project_id = _default.default(quota_project_id="project-foo")
+
+    MOCK_CREDENTIALS.with_quota_project.assert_called_once_with("project-foo")
+    assert project_id == mock.sentinel.project_id
+
+
 @mock.patch(
     "google.auth._default._get_explicit_environ_credentials",
     return_value=(MOCK_CREDENTIALS, mock.sentinel.project_id),

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-localserver responses grpcio flask freezegun mock oauth2client pyopenssl cryptography
3.7
docs/requirements-docs.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
cachetools==4.2.4
certifi @ file:///croot/certifi_1671487769961/work/certifi
cffi==1.15.1
charset-normalizer==3.4.1
click==8.1.8
coverage==7.2.7
cryptography==44.0.2
exceptiongroup==1.2.2
Flask==2.2.5
freezegun==1.5.1
-e git+https://github.com/googleapis/google-auth-library-python.git@9058f1fea680613d9717a62ee37dc294c11b9c8a#egg=google_auth
grpcio==1.62.3
httplib2==0.22.0
idna==3.10
importlib-metadata==6.7.0
iniconfig==2.0.0
itsdangerous==2.1.2
Jinja2==3.1.6
MarkupSafe==2.1.5
mock==5.2.0
oauth2client==4.1.3
oauthlib==3.2.2
packaging==24.0
pluggy==1.2.0
pyasn1==0.5.1
pyasn1-modules==0.3.0
pycparser==2.21
pyOpenSSL==25.0.0
pyparsing==3.1.4
pytest==7.4.4
pytest-cov==4.1.0
pytest-localserver==0.9.0.post0
python-dateutil==2.9.0.post0
PyYAML==6.0.1
requests==2.31.0
requests-oauthlib==2.0.0
responses==0.23.3
rsa==4.9
six==1.17.0
sphinx-docstring-typing==0.0.4
tomli==2.0.1
types-PyYAML==6.0.12.12
typing_extensions==4.7.1
urllib3==2.0.7
Werkzeug==2.2.3
zipp==3.15.0

name: google-auth-library-python
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - cachetools==4.2.4
      - cffi==1.15.1
      - charset-normalizer==3.4.1
      - click==8.1.8
      - coverage==7.2.7
      - cryptography==44.0.2
      - exceptiongroup==1.2.2
      - flask==2.2.5
      - freezegun==1.5.1
      - grpcio==1.62.3
      - httplib2==0.22.0
      - idna==3.10
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - itsdangerous==2.1.2
      - jinja2==3.1.6
      - markupsafe==2.1.5
      - mock==5.2.0
      - oauth2client==4.1.3
      - oauthlib==3.2.2
      - packaging==24.0
      - pluggy==1.2.0
      - pyasn1==0.5.1
      - pyasn1-modules==0.3.0
      - pycparser==2.21
      - pyopenssl==25.0.0
      - pyparsing==3.1.4
      - pytest==7.4.4
      - pytest-cov==4.1.0
      - pytest-localserver==0.9.0.post0
      - python-dateutil==2.9.0.post0
      - pyyaml==6.0.1
      - requests==2.31.0
      - requests-oauthlib==2.0.0
      - responses==0.23.3
      - rsa==4.9
      - six==1.17.0
      - sphinx-docstring-typing==0.0.4
      - tomli==2.0.1
      - types-pyyaml==6.0.12.12
      - typing-extensions==4.7.1
      - urllib3==2.0.7
      - werkzeug==2.2.3
      - zipp==3.15.0
prefix: /opt/conda/envs/google-auth-library-python

tests/test__default.py::test_default_quota_project
tests/test__default.py::test_load_credentials_from_missing_file tests/test__default.py::test_load_credentials_from_file_invalid_json tests/test__default.py::test_load_credentials_from_file_invalid_type tests/test__default.py::test_load_credentials_from_file_authorized_user tests/test__default.py::test_load_credentials_from_file_no_type tests/test__default.py::test_load_credentials_from_file_authorized_user_bad_format tests/test__default.py::test_load_credentials_from_file_authorized_user_cloud_sdk tests/test__default.py::test_load_credentials_from_file_authorized_user_cloud_sdk_with_scopes tests/test__default.py::test_load_credentials_from_file_authorized_user_cloud_sdk_with_quota_project tests/test__default.py::test_load_credentials_from_file_service_account tests/test__default.py::test_load_credentials_from_file_service_account_with_scopes tests/test__default.py::test_load_credentials_from_file_service_account_with_quota_project tests/test__default.py::test_load_credentials_from_file_service_account_bad_format tests/test__default.py::test__get_explicit_environ_credentials_no_env tests/test__default.py::test__get_explicit_environ_credentials tests/test__default.py::test__get_explicit_environ_credentials_no_project_id tests/test__default.py::test__get_gcloud_sdk_credentials tests/test__default.py::test__get_gcloud_sdk_credentials_non_existent tests/test__default.py::test__get_gcloud_sdk_credentials_project_id tests/test__default.py::test__get_gcloud_sdk_credentials_no_project_id tests/test__default.py::test__get_gae_credentials tests/test__default.py::test__get_gae_credentials_no_app_engine tests/test__default.py::test__get_gae_credentials_no_apis tests/test__default.py::test__get_gce_credentials tests/test__default.py::test__get_gce_credentials_no_ping tests/test__default.py::test__get_gce_credentials_no_project_id tests/test__default.py::test__get_gce_credentials_no_compute_engine tests/test__default.py::test__get_gce_credentials_explicit_request tests/test__default.py::test_default_early_out tests/test__default.py::test_default_explict_project_id tests/test__default.py::test_default_explict_legacy_project_id tests/test__default.py::test_default_without_project_id tests/test__default.py::test_default_fail tests/test__default.py::test_default_scoped tests/test__default.py::test_default_no_app_engine_compute_engine_module
google/auth/_default.py
google/auth/_default.py