diff --git a/google/auth/_default.py b/google/auth/_default.py index 356780bf1..b6014e744 100644 --- a/google/auth/_default.py +++ b/google/auth/_default.py @@ -254,7 +254,9 @@ def default(request=None): If no credentials were found, or if the credentials found were invalid. """ - explicit_project_id = os.environ.get(environment_vars.PROJECT) + explicit_project_id = os.environ.get( + environment_vars.PROJECT, + os.environ.get(environment_vars.LEGACY_PROJECT)) checkers = ( _get_explicit_environ_credentials, diff --git a/google/auth/environment_vars.py b/google/auth/environment_vars.py index 9785c3466..b4ed2b28a 100644 --- a/google/auth/environment_vars.py +++ b/google/auth/environment_vars.py @@ -22,6 +22,13 @@ environment variable is also used by the Google Cloud Python Library. """ +LEGACY_PROJECT = 'GCLOUD_PROJECT' +"""Previously used environment variable defining the default project. + +This environment variable is used instead of the current one in some +situations (such as Google App Engine). +""" + CREDENTIALS = 'GOOGLE_APPLICATION_CREDENTIALS' """Environment variable defining the location of Google application default credentials.""" diff --git a/tests/test__default.py b/tests/test__default.py index e244b3de2..c33db1367 100644 --- a/tests/test__default.py +++ b/tests/test__default.py @@ -266,6 +266,15 @@ def test_default_explict_project_id(get_mock, monkeypatch): mock.sentinel.credentials, 'explicit-env') +@mock.patch( + 'google.auth._default._get_explicit_environ_credentials', + return_value=(mock.sentinel.credentials, mock.sentinel.project_id)) +def test_default_explict_legacy_project_id(get_mock, monkeypatch): + monkeypatch.setenv(environment_vars.LEGACY_PROJECT, 'explicit-env') + assert _default.default() == ( + mock.sentinel.credentials, 'explicit-env') + + @mock.patch( 'google.auth._default._get_explicit_environ_credentials', return_value=(None, None))