Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: googleapis/google-auth-library-python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.18.1
Choose a base ref
...
head repository: googleapis/google-auth-library-python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.19.0
Choose a head ref
  • 12 commits
  • 30 files changed
  • 8 contributors

Commits on May 20, 2023

  1. Copy the full SHA
    71debe4 View commit details

Commits on May 22, 2023

  1. chore: token update (#1299)

    * chore: update token
    
    * chore: update token
    BigTailWolf authored May 22, 2023
    Copy the full SHA
    8c8d4e4 View commit details
  2. feat: expose universe_domain for external account creds (#1296)

    * feat: expose  for external account creds
    
    * add universe_domain as info property
    
    * fix info error
    
    * adding coverage of explicit universe_domain assigning
    
    * 🦉 Updates from OwlBot post-processor
    
    See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
    
    ---------
    
    Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
    BigTailWolf and gcf-owl-bot[bot] authored May 22, 2023
    Copy the full SHA
    ee07053 View commit details

Commits on May 23, 2023

  1. chore(deps): bump requests from 2.28.1 to 2.31.0 in /.kokoro (#1302)

    Bumps [requests](https://togithub.com/psf/requests) from 2.28.1 to 2.31.0.
    <details>
    <summary>Release notes</summary>
    <p><em>Sourced from <a href="https://togithub.com/psf/requests/releases">requests's releases</a>.</em></p>
    <blockquote>
    <h2>v2.31.0</h2>
    <h2>2.31.0 (2023-05-22)</h2>
    <p><strong>Security</strong></p>
    <ul>
    <li>
    <p>Versions of Requests between v2.3.0 and v2.30.0 are vulnerable to potential
    forwarding of <code>Proxy-Authorization</code> headers to destination servers when
    following HTTPS redirects.</p>
    <p>When proxies are defined with user info (<a href="https://user:pass@proxy:8080">https://user:pass@proxy:8080</a>), Requests
    will construct a <code>Proxy-Authorization</code> header that is attached to the request to
    authenticate with the proxy.</p>
    <p>In cases where Requests receives a redirect response, it previously reattached
    the <code>Proxy-Authorization</code> header incorrectly, resulting in the value being
    sent through the tunneled connection to the destination server. Users who rely on
    defining their proxy credentials in the URL are <em>strongly</em> encouraged to upgrade
    to Requests 2.31.0+ to prevent unintentional leakage and rotate their proxy
    credentials once the change has been fully deployed.</p>
    <p>Users who do not use a proxy or do not supply their proxy credentials through
    the user information portion of their proxy URL are not subject to this
    vulnerability.</p>
    <p>Full details can be read in our <a href="https://togithub.com/psf/requests/security/advisories/GHSA-j8r2-6x86-q33q">Github Security Advisory</a>
    and <a href="https://nvd.nist.gov/vuln/detail/CVE-2023-32681">CVE-2023-32681</a>.</p>
    </li>
    </ul>
    <h2>v2.30.0</h2>
    <h2>2.30.0 (2023-05-03)</h2>
    <p><strong>Dependencies</strong></p>
    <ul>
    <li>
    <p>⚠️ Added support for urllib3 2.0. ⚠️</p>
    <p>This may contain minor breaking changes so we advise careful testing and
    reviewing <a href="https://urllib3.readthedocs.io/en/latest/v2-migration-guide.html">https://urllib3.readthedocs.io/en/latest/v2-migration-guide.html</a>
    prior to upgrading.</p>
    <p>Users who wish to stay on urllib3 1.x can pin to <code>urllib3&lt;2</code>.</p>
    </li>
    </ul>
    <h2>v2.29.0</h2>
    <h2>2.29.0 (2023-04-26)</h2>
    <p><strong>Improvements</strong></p>
    <ul>
    <li>Requests now defers chunked requests to the urllib3 implementation to improve
    standardization. (<a href="https://redirect.github.com/psf/requests/issues/6226">#6226</a>)</li>
    <li>Requests relaxes header component requirements to support bytes/str subclasses. (<a href="https://redirect.github.com/psf/requests/issues/6356">#6356</a>)</li>
    </ul>
    <!-- raw HTML omitted -->
    </blockquote>
    <p>... (truncated)</p>
    </details>
    <details>
    <summary>Changelog</summary>
    <p><em>Sourced from <a href="https://togithub.com/psf/requests/blob/main/HISTORY.md">requests's changelog</a>.</em></p>
    <blockquote>
    <h2>2.31.0 (2023-05-22)</h2>
    <p><strong>Security</strong></p>
    <ul>
    <li>
    <p>Versions of Requests between v2.3.0 and v2.30.0 are vulnerable to potential
    forwarding of <code>Proxy-Authorization</code> headers to destination servers when
    following HTTPS redirects.</p>
    <p>When proxies are defined with user info (<a href="https://user:pass@proxy:8080">https://user:pass@proxy:8080</a>), Requests
    will construct a <code>Proxy-Authorization</code> header that is attached to the request to
    authenticate with the proxy.</p>
    <p>In cases where Requests receives a redirect response, it previously reattached
    the <code>Proxy-Authorization</code> header incorrectly, resulting in the value being
    sent through the tunneled connection to the destination server. Users who rely on
    defining their proxy credentials in the URL are <em>strongly</em> encouraged to upgrade
    to Requests 2.31.0+ to prevent unintentional leakage and rotate their proxy
    credentials once the change has been fully deployed.</p>
    <p>Users who do not use a proxy or do not supply their proxy credentials through
    the user information portion of their proxy URL are not subject to this
    vulnerability.</p>
    <p>Full details can be read in our <a href="https://togithub.com/psf/requests/security/advisories/GHSA-j8r2-6x86-q33q">Github Security Advisory</a>
    and <a href="https://nvd.nist.gov/vuln/detail/CVE-2023-32681">CVE-2023-32681</a>.</p>
    </li>
    </ul>
    <h2>2.30.0 (2023-05-03)</h2>
    <p><strong>Dependencies</strong></p>
    <ul>
    <li>
    <p>⚠️ Added support for urllib3 2.0. ⚠️</p>
    <p>This may contain minor breaking changes so we advise careful testing and
    reviewing <a href="https://urllib3.readthedocs.io/en/latest/v2-migration-guide.html">https://urllib3.readthedocs.io/en/latest/v2-migration-guide.html</a>
    prior to upgrading.</p>
    <p>Users who wish to stay on urllib3 1.x can pin to <code>urllib3&lt;2</code>.</p>
    </li>
    </ul>
    <h2>2.29.0 (2023-04-26)</h2>
    <p><strong>Improvements</strong></p>
    <ul>
    <li>Requests now defers chunked requests to the urllib3 implementation to improve
    standardization. (<a href="https://redirect.github.com/psf/requests/issues/6226">#6226</a>)</li>
    <li>Requests relaxes header component requirements to support bytes/str subclasses. (<a href="https://redirect.github.com/psf/requests/issues/6356">#6356</a>)</li>
    </ul>
    <h2>2.28.2 (2023-01-12)</h2>
    <!-- raw HTML omitted -->
    </blockquote>
    <p>... (truncated)</p>
    </details>
    <details>
    <summary>Commits</summary>
    <ul>
    <li><a href="https://togithub.com/psf/requests/commit/147c8511ddbfa5e8f71bbf5c18ede0c4ceb3bba4"><code>147c851</code></a> v2.31.0</li>
    <li><a href="https://togithub.com/psf/requests/commit/74ea7cf7a6a27a4eeb2ae24e162bcc942a6706d5"><code>74ea7cf</code></a> Merge pull request from GHSA-j8r2-6x86-q33q</li>
    <li><a href="https://togithub.com/psf/requests/commit/302225334678490ec66b3614a9dddb8a02c5f4fe"><code>3022253</code></a> test on pypy 3.8 and pypy 3.9 on windows and macos (<a href="https://redirect.github.com/psf/requests/issues/6424">#6424</a>)</li>
    <li><a href="https://togithub.com/psf/requests/commit/b639e66c816514e40604d46f0088fbceec1a5149"><code>b639e66</code></a> test on py3.12 (<a href="https://redirect.github.com/psf/requests/issues/6448">#6448</a>)</li>
    <li><a href="https://togithub.com/psf/requests/commit/d3d504436ef0c2ac7ec8af13738b04dcc8c694be"><code>d3d5044</code></a> Fixed a small typo (<a href="https://redirect.github.com/psf/requests/issues/6452">#6452</a>)</li>
    <li><a href="https://togithub.com/psf/requests/commit/2ad18e0e10e7d7ecd5384c378f25ec8821a10a29"><code>2ad18e0</code></a> v2.30.0</li>
    <li><a href="https://togithub.com/psf/requests/commit/f2629e9e3c7ce3c3c8c025bcd8db551101cbc773"><code>f2629e9</code></a> Remove strict parameter (<a href="https://redirect.github.com/psf/requests/issues/6434">#6434</a>)</li>
    <li><a href="https://togithub.com/psf/requests/commit/87d63de8739263bbe17034fba2285c79780da7e8"><code>87d63de</code></a> v2.29.0</li>
    <li><a href="https://togithub.com/psf/requests/commit/51716c4ef390136b0d4b800ec7665dd5503e64fc"><code>51716c4</code></a> enable the warnings plugin (<a href="https://redirect.github.com/psf/requests/issues/6416">#6416</a>)</li>
    <li><a href="https://togithub.com/psf/requests/commit/a7da1ab3498b10ec3a3582244c94b2845f8a8e71"><code>a7da1ab</code></a> try on ubuntu 22.04 (<a href="https://redirect.github.com/psf/requests/issues/6418">#6418</a>)</li>
    <li>Additional commits viewable in <a href="https://togithub.com/psf/requests/compare/v2.28.1...v2.31.0">compare view</a></li>
    </ul>
    </details>
    <br />
    
    
    [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=requests&package-manager=pip&previous-version=2.28.1&new-version=2.31.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
    
    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
    
    [//]: # (dependabot-automerge-start)
    [//]: # (dependabot-automerge-end)
    
    ---
    
    <details>
    <summary>Dependabot commands and options</summary>
    <br />
    
    You can trigger Dependabot actions by commenting on this PR:
    - `@dependabot rebase` will rebase this PR
    - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
    - `@dependabot merge` will merge this PR after your CI passes on it
    - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
    - `@dependabot cancel merge` will cancel a previously requested merge and block automerging
    - `@dependabot reopen` will reopen this PR if it is closed
    - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    You can disable automated security fix PRs for this repo from the [Security Alerts page](https://togithub.com/googleapis/google-auth-library-python/network/alerts).
    
    </details>
    dependabot[bot] authored May 23, 2023
    Copy the full SHA
    3bac683 View commit details
  2. feat: add metrics (part 1) (#1298)

    This PR:
    (1) list the metrics values needed
    (2) add the `_metric_header_for_usage` method to the base credential class, which is used by the `before_request` method to add the metrics header for token usage. Children credentials classes can override this method for token usage metrics.
    
    internal doc: go/googleapis-auth-metric-design
    arithmetic1728 authored May 23, 2023
    Copy the full SHA
    246dd07 View commit details

Commits on May 24, 2023

  1. Copy the full SHA
    ebd5af7 View commit details

Commits on May 25, 2023

  1. Copy the full SHA
    75878c8 View commit details
  2. feat: remove python 2.7 from setup.py and nox tests (#1301)

    * feat: remove python 2.7 from setup.py and nox tests. Originally done in #892
    clundin25 authored May 25, 2023
    Copy the full SHA
    8437490 View commit details
  3. build(deps): bump requests from 2.28.1 to 2.31.0 in /synthtool/gcp/te…

    …mplates/python_library/.kokoro (#1307)
    
    Source-Link: googleapis/synthtool@30bd01b
    Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:9bc5fa3b62b091f60614c08a7fb4fd1d3e1678e326f34dd66ce1eefb5dc3267b
    
    Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
    Co-authored-by: Anthonios Partheniou <partheniou@google.com>
    3 people authored May 25, 2023
    Copy the full SHA
    5f3dd94 View commit details
  4. feat: add metrics (part 3) (#1305)

    This PR adds `x-goog-api-client` header to
    - access token and id token refresh requests, for compute engine credentials / user credentials / service account credentials / impersonated credentials
    - reauth start and continue requests
    - metadata server ping requests
    
    Previous PRs:
    Part 1: #1298 
    Part 2: #1303
    arithmetic1728 authored May 25, 2023
    Copy the full SHA
    c7011b6 View commit details
  5. Copy the full SHA
    d137792 View commit details
  6. chore(main): release 2.19.0 (#1300)

    Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
    Co-authored-by: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com>
    release-please[bot] and arithmetic1728 authored May 25, 2023
    Copy the full SHA
    9c87ad0 View commit details
3 changes: 2 additions & 1 deletion .github/.OwlBot.lock.yaml
Original file line number Diff line number Diff line change
@@ -13,4 +13,5 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
digest: sha256:2e247c7bf5154df7f98cce087a20ca7605e236340c7d6d1a14447e5c06791bd6
digest: sha256:9bc5fa3b62b091f60614c08a7fb4fd1d3e1678e326f34dd66ce1eefb5dc3267b
# created: 2023-05-25T14:56:16.294623272Z
6 changes: 3 additions & 3 deletions .kokoro/requirements.txt
Original file line number Diff line number Diff line change
@@ -419,9 +419,9 @@ readme-renderer==37.3 \
--hash=sha256:cd653186dfc73055656f090f227f5cb22a046d7f71a841dfa305f55c9a513273 \
--hash=sha256:f67a16caedfa71eef48a31b39708637a6f4664c4394801a7b0d6432d13907343
# via twine
requests==2.28.1 \
--hash=sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983 \
--hash=sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349
requests==2.31.0 \
--hash=sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f \
--hash=sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1
# via
# gcp-releasetool
# google-api-core
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,17 @@

[1]: https://pypi.org/project/google-auth/#history

## [2.19.0](https://github.com/googleapis/google-auth-library-python/compare/v2.18.1...v2.19.0) (2023-05-25)


### Features

* Add metrics (part 1) ([#1298](https://github.com/googleapis/google-auth-library-python/issues/1298)) ([246dd07](https://github.com/googleapis/google-auth-library-python/commit/246dd079388e21036831e2ebc7586c9f596acbec))
* Add metrics (part 2) ([#1303](https://github.com/googleapis/google-auth-library-python/issues/1303)) ([ebd5af7](https://github.com/googleapis/google-auth-library-python/commit/ebd5af7d372d4cde892601138de282217586135f))
* Add metrics (part 3) ([#1305](https://github.com/googleapis/google-auth-library-python/issues/1305)) ([c7011b6](https://github.com/googleapis/google-auth-library-python/commit/c7011b6d3dba479390ce08a96ac1923de2a4e8b4))
* Expose `universe_domain` for external account creds ([#1296](https://github.com/googleapis/google-auth-library-python/issues/1296)) ([ee07053](https://github.com/googleapis/google-auth-library-python/commit/ee070535ce06661eeb12e407e782c155b142cecf))
* Remove python 2.7 from setup.py and nox tests ([#1301](https://github.com/googleapis/google-auth-library-python/issues/1301)) ([8437490](https://github.com/googleapis/google-auth-library-python/commit/84374903f418535d17811690632be9395403afaf))

## [2.18.1](https://github.com/googleapis/google-auth-library-python/compare/v2.18.0...v2.18.1) (2023-05-17)


30 changes: 23 additions & 7 deletions google/auth/compute_engine/_metadata.py
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
from google.auth import _helpers
from google.auth import environment_vars
from google.auth import exceptions
from google.auth import metrics

_LOGGER = logging.getLogger(__name__)

@@ -121,13 +122,13 @@ def ping(request, timeout=_METADATA_DEFAULT_TIMEOUT, retry_count=3):
# the metadata resolution was particularly slow. The latter case is
# "unlikely".
retries = 0
headers = _METADATA_HEADERS.copy()
headers[metrics.API_CLIENT_HEADER] = metrics.mds_ping()

while retries < retry_count:
try:
response = request(
url=_METADATA_IP_ROOT,
method="GET",
headers=_METADATA_HEADERS,
timeout=timeout,
url=_METADATA_IP_ROOT, method="GET", headers=headers, timeout=timeout
)

metadata_flavor = response.headers.get(_METADATA_FLAVOR_HEADER)
@@ -150,7 +151,13 @@ def ping(request, timeout=_METADATA_DEFAULT_TIMEOUT, retry_count=3):


def get(
request, path, root=_METADATA_ROOT, params=None, recursive=False, retry_count=5
request,
path,
root=_METADATA_ROOT,
params=None,
recursive=False,
retry_count=5,
headers=None,
):
"""Fetch a resource from the metadata server.
@@ -167,6 +174,7 @@ def get(
details.
retry_count (int): How many times to attempt connecting to metadata
server using above timeout.
headers (Optional[Mapping[str, str]]): Headers for the request.
Returns:
Union[Mapping, str]: If the metadata server returns JSON, a mapping of
@@ -180,6 +188,10 @@ def get(
base_url = urlparse.urljoin(root, path)
query_params = {} if params is None else params

headers_to_use = _METADATA_HEADERS.copy()
if headers:
headers_to_use.update(headers)

if recursive:
query_params["recursive"] = "true"

@@ -188,7 +200,7 @@ def get(
retries = 0
while retries < retry_count:
try:
response = request(url=url, method="GET", headers=_METADATA_HEADERS)
response = request(url=url, method="GET", headers=headers_to_use)
break

except exceptions.TransportError as e:
@@ -300,8 +312,12 @@ def get_service_account_token(request, service_account="default", scopes=None):
else:
params = None

metrics_header = {
metrics.API_CLIENT_HEADER: metrics.token_request_access_token_mds()
}

path = "instance/service-accounts/{0}/token".format(service_account)
token_json = get(request, path, params=params)
token_json = get(request, path, params=params, headers=metrics_header)
token_expiry = _helpers.utcnow() + datetime.timedelta(
seconds=token_json["expires_in"]
)
11 changes: 10 additions & 1 deletion google/auth/compute_engine/credentials.py
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
from google.auth import exceptions
from google.auth import iam
from google.auth import jwt
from google.auth import metrics
from google.auth.compute_engine import _metadata
from google.oauth2 import _client

@@ -94,6 +95,9 @@ def _retrieve_info(self, request):
if self._scopes is None:
self._scopes = info["scopes"]

def _metric_header_for_usage(self):
return metrics.CRED_TYPE_SA_MDS

def refresh(self, request):
"""Refresh the access token and scopes.
@@ -374,7 +378,12 @@ def _call_metadata_identity_endpoint(self, request):
try:
path = "instance/service-accounts/default/identity"
params = {"audience": self._target_audience, "format": "full"}
id_token = _metadata.get(request, path, params=params)
metrics_header = {
metrics.API_CLIENT_HEADER: metrics.token_request_id_token_mds()
}
id_token = _metadata.get(
request, path, params=params, headers=metrics_header
)
except exceptions.TransportError as caught_exc:
new_exc = exceptions.RefreshError(caught_exc)
six.raise_from(new_exc, caught_exc)
17 changes: 17 additions & 0 deletions google/auth/credentials.py
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@

from google.auth import _helpers, environment_vars
from google.auth import exceptions
from google.auth import metrics


@six.add_metaclass(abc.ABCMeta)
@@ -100,6 +101,21 @@ def refresh(self, request):
# (pylint doesn't recognize that this is abstract)
raise NotImplementedError("Refresh must be implemented")

def _metric_header_for_usage(self):
"""The x-goog-api-client header for token usage metric.
This header will be added to the API service requests in before_request
method. For example, "cred-type/sa-jwt" means service account self
signed jwt access token is used in the API service request
authorization header. Children credentials classes need to override
this method to provide the header value, if the token usage metric is
needed.
Returns:
str: The x-goog-api-client header value.
"""
return None

def apply(self, headers, token=None):
"""Apply the token to the authentication header.
@@ -133,6 +149,7 @@ def before_request(self, request, method, url, headers):
# the http request.)
if not self.valid:
self.refresh(request)
metrics.add_metric_header(headers, self._metric_header_for_usage())
self.apply(headers)


8 changes: 8 additions & 0 deletions google/auth/external_account.py
Original file line number Diff line number Diff line change
@@ -52,6 +52,8 @@
# Cloud resource manager URL used to retrieve project information.
_CLOUD_RESOURCE_MANAGER = "https://cloudresourcemanager.googleapis.com/v1/projects/"

_DEFAULT_UNIVERSE_DOMAIN = "googleapis.com"


@six.add_metaclass(abc.ABCMeta)
class Credentials(
@@ -82,6 +84,7 @@ def __init__(
scopes=None,
default_scopes=None,
workforce_pool_user_project=None,
universe_domain=_DEFAULT_UNIVERSE_DOMAIN,
):
"""Instantiates an external account credentials object.
@@ -105,6 +108,8 @@ def __init__(
a workload identity pool. The underlying principal must still have
serviceusage.services.use IAM permission to use the project for
billing/quota.
universe_domain (str): The universe domain. The default universe
domain is googleapis.com.
Raises:
google.auth.exceptions.RefreshError: If the generateAccessToken
endpoint returned an error.
@@ -125,6 +130,7 @@ def __init__(
self._scopes = scopes
self._default_scopes = default_scopes
self._workforce_pool_user_project = workforce_pool_user_project
self._universe_domain = universe_domain or _DEFAULT_UNIVERSE_DOMAIN

if self._client_id:
self._client_auth = utils.ClientAuthentication(
@@ -186,6 +192,7 @@ def _constructor_args(self):
"workforce_pool_user_project": self._workforce_pool_user_project,
"scopes": self._scopes,
"default_scopes": self._default_scopes,
"universe_domain": self._universe_domain,
}
if not self.is_workforce_pool:
args.pop("workforce_pool_user_project")
@@ -458,6 +465,7 @@ def from_info(cls, info, **kwargs):
credential_source=info.get("credential_source"),
quota_project_id=info.get("quota_project_id"),
workforce_pool_user_project=info.get("workforce_pool_user_project"),
universe_domain=info.get("universe_domain", _DEFAULT_UNIVERSE_DOMAIN),
**kwargs
)

14 changes: 12 additions & 2 deletions google/auth/impersonated_credentials.py
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@
from google.auth import credentials
from google.auth import exceptions
from google.auth import jwt
from google.auth import metrics

_DEFAULT_TOKEN_LIFETIME_SECS = 3600 # 1 hour in seconds

@@ -238,6 +239,9 @@ def __init__(
self._quota_project_id = quota_project_id
self._iam_endpoint_override = iam_endpoint_override

def _metric_header_for_usage(self):
return metrics.CRED_TYPE_SA_IMPERSONATE

@_helpers.copy_docstring(credentials.Credentials)
def refresh(self, request):
self._update_token(request)
@@ -261,7 +265,10 @@ def _update_token(self, request):
"lifetime": str(self._lifetime) + "s",
}

headers = {"Content-Type": "application/json"}
headers = {
"Content-Type": "application/json",
metrics.API_CLIENT_HEADER: metrics.token_request_access_token_impersonate(),
}

# Apply the source credentials authentication info.
self._source_credentials.apply(headers)
@@ -422,7 +429,10 @@ def refresh(self, request):
"includeEmail": self._include_email,
}

headers = {"Content-Type": "application/json"}
headers = {
"Content-Type": "application/json",
metrics.API_CLIENT_HEADER: metrics.token_request_id_token_impersonate(),
}

authed_session = AuthorizedSession(
self._target_credentials._source_credentials, auth_request=request
Loading