Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding more properties to external_account_authorized_user #1169

Merged
merged 10 commits into from
Oct 29, 2022
23 changes: 23 additions & 0 deletions google/auth/external_account_authorized_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(
token_url=None,
token_info_url=None,
revoke_url=None,
scopes=None,
lsirac marked this conversation as resolved.
Show resolved Hide resolved
quota_project_id=None,
):
"""Instantiates a external account authorized user credentials object.
Expand Down Expand Up @@ -117,6 +118,7 @@ def __init__(
self._client_secret = client_secret
self._revoke_url = revoke_url
self._quota_project_id = quota_project_id
self._scopes = scopes
ScruffyProdigy marked this conversation as resolved.
Show resolved Hide resolved

self._client_auth = None
if self._client_id:
Expand Down Expand Up @@ -154,20 +156,41 @@ def constructor_args(self):
"token": self.token,
"expiry": self.expiry,
"revoke_url": self._revoke_url,
"scopes": self._scopes,
"quota_project_id": self._quota_project_id,
}

@property
def scopes(self):
ScruffyProdigy marked this conversation as resolved.
Show resolved Hide resolved
"""Optional[str]: The OAuth 2.0 permission scopes."""
return self._scopes

@property
def requires_scopes(self):
""" False: OAuth 2.0 credentials have their scopes set when
the initial token is requested and can not be changed."""
return False

@property
def client_id(self):
"""Optional[str]: The OAuth 2.0 client ID."""
return self._client_id

@property
def client_secret(self):
"""Optional[str]: The OAuth 2.0 client secret."""
return self._client_secret

@property
def is_user(self):
""" True: This credential always represents a user."""
return True

@property
def token_info_url(self):
ScruffyProdigy marked this conversation as resolved.
Show resolved Hide resolved
ScruffyProdigy marked this conversation as resolved.
Show resolved Hide resolved
"""Optional[str]: The STS endpoint for token info."""
return self._token_info_url

def get_project_id(self):
"""Retrieves the project ID corresponding to the workload identity or workforce pool.
For workforce pool credentials, it returns the project ID corresponding to
Expand Down
8 changes: 7 additions & 1 deletion tests/test_external_account_authorized_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
CLIENT_SECRET = "password"
# Base64 encoding of "username:password".
BASIC_AUTH_ENCODING = "dXNlcm5hbWU6cGFzc3dvcmQ="
SCOPES = ["email", "profile"]


class TestCredentials(object):
Expand Down Expand Up @@ -87,18 +88,23 @@ def test_default_state(self):
assert not creds.token
assert not creds.valid
assert not creds.requires_scopes
assert not creds.scopes
assert creds.token_info_url
assert creds.client_id
assert creds.client_secret
assert creds.is_user

def test_basic_create(self):
creds = external_account_authorized_user.Credentials(
token=ACCESS_TOKEN, expiry=datetime.datetime.max
token=ACCESS_TOKEN, expiry=datetime.datetime.max, scopes=SCOPES,
)

assert creds.expiry == datetime.datetime.max
assert not creds.expired
assert creds.token == ACCESS_TOKEN
assert creds.valid
assert not creds.requires_scopes
assert creds.scopes == SCOPES
assert creds.is_user

def test_stunted_create(self):
Expand Down