Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 2 packages/google-auth/google/auth/impersonated_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ def sign_bytes(self, message):
headers = {"Content-Type": "application/json"}

authed_session = AuthorizedSession(self._source_credentials)
authed_session.configure_mtls_channel()

try:
retries = _exponential_backoff.ExponentialBackoff()
Expand Down Expand Up @@ -627,6 +628,7 @@ def refresh(self, request):
authed_session = AuthorizedSession(
self._target_credentials._source_credentials, auth_request=request
)
authed_session.configure_mtls_channel()

try:
response = authed_session.post(
Expand Down
29 changes: 29 additions & 0 deletions 29 packages/google-auth/tests/test_impersonated_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,19 @@ def _sign_bytes_helper(

assert signature == b"signature"

@mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel", autospec=True)
def test_sign_bytes_configures_mtls(self, mock_configure_mtls, mock_donor_credentials, mock_authorizedsession_sign):
credentials = self.make_credentials(lifetime=None)
# Refresh is needed to make credentials valid before signing
request = self.make_request(
data=json.dumps({"accessToken": "token", "expireTime": "2026-06-09T00:00:00Z"}),
status=http_client.OK,
)
credentials.refresh(request)

credentials.sign_bytes(b"signed bytes")
mock_configure_mtls.assert_called_once()

def test_sign_bytes_failure(self):
credentials = self.make_credentials(lifetime=None)

Expand Down Expand Up @@ -751,6 +764,22 @@ def test_with_scopes_provide_default_scopes(self):
)
assert credentials._target_scopes == ["fake_scope1"]

@mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel", autospec=True)
def test_id_token_refresh_configures_mtls(self, mock_configure_mtls, mock_donor_credentials):
credentials = self.make_credentials(lifetime=None)
credentials.token = "token"
id_creds = impersonated_credentials.IDTokenCredentials(
credentials, target_audience="https://foo.bar"
)

with mock.patch(
"google.auth.transport.requests.AuthorizedSession.post", autospec=True
) as mock_post:
mock_post.return_value = MockResponse({"token": ID_TOKEN_DATA}, http_client.OK)
id_creds.refresh(None)

mock_configure_mtls.assert_called_once()

def test_id_token_success(
self, mock_donor_credentials, mock_authorizedsession_idtoken
):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.