diff --git a/google/oauth2/credentials.py b/google/oauth2/credentials.py index 76ac878cc..5c40ab097 100644 --- a/google/oauth2/credentials.py +++ b/google/oauth2/credentials.py @@ -35,6 +35,7 @@ import io import json import logging +import warnings import six @@ -498,6 +499,13 @@ class UserAccessTokenCredentials(credentials.CredentialsWithQuotaProject): """ def __init__(self, account=None, quota_project_id=None): + warnings.warn( + "UserAccessTokenCredentials is deprecated, please use " + "google.oauth2.credentials.Credentials instead. To use " + "that credential type, simply run " + "`gcloud auth application-default login` and let the " + "client libraries pick up the application default credentials." + ) super(UserAccessTokenCredentials, self).__init__() self._account = account self._quota_project_id = quota_project_id diff --git a/system_tests/secrets.tar.enc b/system_tests/secrets.tar.enc index 4e6ffb1c4..0c81b08f5 100644 Binary files a/system_tests/secrets.tar.enc and b/system_tests/secrets.tar.enc differ diff --git a/tests/oauth2/test_credentials.py b/tests/oauth2/test_credentials.py index feb7e4311..d265d22ed 100644 --- a/tests/oauth2/test_credentials.py +++ b/tests/oauth2/test_credentials.py @@ -951,25 +951,34 @@ def test_unpickle_old_credentials_pickle(self): class TestUserAccessTokenCredentials(object): def test_instance(self): - cred = credentials.UserAccessTokenCredentials() - assert cred._account is None + with pytest.warns( + UserWarning, match="UserAccessTokenCredentials is deprecated" + ): + cred = credentials.UserAccessTokenCredentials() + assert cred._account is None - cred = cred.with_account("account") - assert cred._account == "account" + cred = cred.with_account("account") + assert cred._account == "account" @mock.patch("google.auth._cloud_sdk.get_auth_access_token", autospec=True) def test_refresh(self, get_auth_access_token): - get_auth_access_token.return_value = "access_token" - cred = credentials.UserAccessTokenCredentials() - cred.refresh(None) - assert cred.token == "access_token" + with pytest.warns( + UserWarning, match="UserAccessTokenCredentials is deprecated" + ): + get_auth_access_token.return_value = "access_token" + cred = credentials.UserAccessTokenCredentials() + cred.refresh(None) + assert cred.token == "access_token" def test_with_quota_project(self): - cred = credentials.UserAccessTokenCredentials() - quota_project_cred = cred.with_quota_project("project-foo") + with pytest.warns( + UserWarning, match="UserAccessTokenCredentials is deprecated" + ): + cred = credentials.UserAccessTokenCredentials() + quota_project_cred = cred.with_quota_project("project-foo") - assert quota_project_cred._quota_project_id == "project-foo" - assert quota_project_cred._account == cred._account + assert quota_project_cred._quota_project_id == "project-foo" + assert quota_project_cred._account == cred._account @mock.patch( "google.oauth2.credentials.UserAccessTokenCredentials.apply", autospec=True @@ -978,7 +987,10 @@ def test_with_quota_project(self): "google.oauth2.credentials.UserAccessTokenCredentials.refresh", autospec=True ) def test_before_request(self, refresh, apply): - cred = credentials.UserAccessTokenCredentials() - cred.before_request(mock.Mock(), "GET", "https://example.com", {}) - refresh.assert_called() - apply.assert_called() + with pytest.warns( + UserWarning, match="UserAccessTokenCredentials is deprecated" + ): + cred = credentials.UserAccessTokenCredentials() + cred.before_request(mock.Mock(), "GET", "https://example.com", {}) + refresh.assert_called() + apply.assert_called()