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

feat: adds new external account authorized user credentials #1160

Merged
merged 21 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions google/auth/external_account_authorized_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

_EXTERNAL_ACCOUNT_AUTHORIZED_USER_JSON_TYPE = "external_account_authorized_user"


class Credentials(
credentials.CredentialsWithQuotaProject,
credentials.ReadOnlyScoped,
Expand Down Expand Up @@ -155,6 +156,9 @@ def is_user(self):
def get_project_id(self):
return None

def to_json(self):
ScruffyProdigy marked this conversation as resolved.
Show resolved Hide resolved
return json.dumps(self.info)

def refresh(self, request):
now = _helpers.utcnow()
response_data = self._make_sts_request(request)
Expand Down
41 changes: 39 additions & 2 deletions tests/test_external_account_authorized_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,43 @@ def test_info_full(self):
assert info["revoke_url"] == self.REVOKE_URL
assert info["quota_project_id"] == self.QUOTA_PROJECT_ID

def test_to_json(self):
creds = self.make_credentials()
json_info = creds.to_json()
info = json.loads(json_info)

assert info["audience"] == self.AUDIENCE
assert info["refresh_token"] == self.REFRESH_TOKEN
assert info["token_url"] == self.TOKEN_URL
assert info["token_info_url"] == self.TOKEN_INFO_URL
assert info["client_id"] == self.CLIENT_ID
assert info["client_secret"] == self.CLIENT_SECRET
assert "token" not in info
assert "expiry" not in info
assert "revoke_url" not in info
assert "quota_project_id" not in info

def test_to_json_full(self):
creds = self.make_credentials(
token=self.ACCESS_TOKEN,
expiry=datetime.datetime.min,
revoke_url=self.REVOKE_URL,
quota_project_id=self.QUOTA_PROJECT_ID,
)
json_info = creds.to_json()
info = json.loads(json_info)

assert info["audience"] == self.AUDIENCE
assert info["refresh_token"] == self.REFRESH_TOKEN
assert info["token_url"] == self.TOKEN_URL
assert info["token_info_url"] == self.TOKEN_INFO_URL
assert info["client_id"] == self.CLIENT_ID
assert info["client_secret"] == self.CLIENT_SECRET
assert info["token"] == self.ACCESS_TOKEN
assert info["expiry"] == datetime.datetime.min.isoformat() + "Z"
assert info["revoke_url"] == self.REVOKE_URL
assert info["quota_project_id"] == self.QUOTA_PROJECT_ID

def test_get_project_id(self):
creds = self.make_credentials()
assert creds.get_project_id() is None
Expand Down Expand Up @@ -276,7 +313,7 @@ def test_with_token_uri(self):
def test_from_file_required_options_only(self, tmpdir):
from_creds = self.make_credentials()
config_file = tmpdir.join("config.json")
config_file.write(json.dumps(from_creds.info))
config_file.write(from_creds.to_json())
creds = external_account_authorized_user.Credentials.from_file(str(config_file))

assert isinstance(creds, external_account_authorized_user.Credentials)
Expand All @@ -299,7 +336,7 @@ def test_from_file_full_options(self, tmpdir):
quota_project_id=self.QUOTA_PROJECT_ID,
)
config_file = tmpdir.join("config.json")
config_file.write(json.dumps(from_creds.info))
config_file.write(from_creds.to_json())
creds = external_account_authorized_user.Credentials.from_file(str(config_file))

assert isinstance(creds, external_account_authorized_user.Credentials)
Expand Down