Skip to content

Commit 399395a

Browse files
fix: deprecate UserAccessTokenCredentials (#1344)
1 parent 4211b23 commit 399395a

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

packages/google-auth/google/oauth2/credentials.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io
3636
import json
3737
import logging
38+
import warnings
3839

3940
import six
4041

@@ -498,6 +499,13 @@ class UserAccessTokenCredentials(credentials.CredentialsWithQuotaProject):
498499
"""
499500

500501
def __init__(self, account=None, quota_project_id=None):
502+
warnings.warn(
503+
"UserAccessTokenCredentials is deprecated, please use "
504+
"google.oauth2.credentials.Credentials instead. To use "
505+
"that credential type, simply run "
506+
"`gcloud auth application-default login` and let the "
507+
"client libraries pick up the application default credentials."
508+
)
501509
super(UserAccessTokenCredentials, self).__init__()
502510
self._account = account
503511
self._quota_project_id = quota_project_id
0 Bytes
Binary file not shown.

packages/google-auth/tests/oauth2/test_credentials.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -951,25 +951,34 @@ def test_unpickle_old_credentials_pickle(self):
951951

952952
class TestUserAccessTokenCredentials(object):
953953
def test_instance(self):
954-
cred = credentials.UserAccessTokenCredentials()
955-
assert cred._account is None
954+
with pytest.warns(
955+
UserWarning, match="UserAccessTokenCredentials is deprecated"
956+
):
957+
cred = credentials.UserAccessTokenCredentials()
958+
assert cred._account is None
956959

957-
cred = cred.with_account("account")
958-
assert cred._account == "account"
960+
cred = cred.with_account("account")
961+
assert cred._account == "account"
959962

960963
@mock.patch("google.auth._cloud_sdk.get_auth_access_token", autospec=True)
961964
def test_refresh(self, get_auth_access_token):
962-
get_auth_access_token.return_value = "access_token"
963-
cred = credentials.UserAccessTokenCredentials()
964-
cred.refresh(None)
965-
assert cred.token == "access_token"
965+
with pytest.warns(
966+
UserWarning, match="UserAccessTokenCredentials is deprecated"
967+
):
968+
get_auth_access_token.return_value = "access_token"
969+
cred = credentials.UserAccessTokenCredentials()
970+
cred.refresh(None)
971+
assert cred.token == "access_token"
966972

967973
def test_with_quota_project(self):
968-
cred = credentials.UserAccessTokenCredentials()
969-
quota_project_cred = cred.with_quota_project("project-foo")
974+
with pytest.warns(
975+
UserWarning, match="UserAccessTokenCredentials is deprecated"
976+
):
977+
cred = credentials.UserAccessTokenCredentials()
978+
quota_project_cred = cred.with_quota_project("project-foo")
970979

971-
assert quota_project_cred._quota_project_id == "project-foo"
972-
assert quota_project_cred._account == cred._account
980+
assert quota_project_cred._quota_project_id == "project-foo"
981+
assert quota_project_cred._account == cred._account
973982

974983
@mock.patch(
975984
"google.oauth2.credentials.UserAccessTokenCredentials.apply", autospec=True
@@ -978,7 +987,10 @@ def test_with_quota_project(self):
978987
"google.oauth2.credentials.UserAccessTokenCredentials.refresh", autospec=True
979988
)
980989
def test_before_request(self, refresh, apply):
981-
cred = credentials.UserAccessTokenCredentials()
982-
cred.before_request(mock.Mock(), "GET", "https://example.com", {})
983-
refresh.assert_called()
984-
apply.assert_called()
990+
with pytest.warns(
991+
UserWarning, match="UserAccessTokenCredentials is deprecated"
992+
):
993+
cred = credentials.UserAccessTokenCredentials()
994+
cred.before_request(mock.Mock(), "GET", "https://example.com", {})
995+
refresh.assert_called()
996+
apply.assert_called()

0 commit comments

Comments
 (0)