google-auth 2.60.0__tar.gz → 2.62.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. {google_auth-2.60.0/google_auth.egg-info → google_auth-2.62.0}/PKG-INFO +1 -2
  2. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_agent_identity_utils.py +105 -53
  3. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/aio/transport/sessions.py +3 -13
  4. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/compute_engine/_metadata.py +65 -16
  5. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/compute_engine/credentials.py +63 -52
  6. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/environment_vars.py +13 -1
  7. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/identity_pool.py +5 -4
  8. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/transport/_mtls_helper.py +108 -31
  9. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/transport/mtls.py +15 -4
  10. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/version.py +1 -1
  11. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/_id_token_async.py +21 -2
  12. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/id_token.py +38 -4
  13. {google_auth-2.60.0 → google_auth-2.62.0/google_auth.egg-info}/PKG-INFO +1 -2
  14. {google_auth-2.60.0 → google_auth-2.62.0}/google_auth.egg-info/requires.txt +0 -1
  15. {google_auth-2.60.0 → google_auth-2.62.0}/setup.py +2 -2
  16. {google_auth-2.60.0 → google_auth-2.62.0}/tests/compute_engine/test__metadata.py +92 -41
  17. {google_auth-2.60.0 → google_auth-2.62.0}/tests/compute_engine/test_credentials.py +343 -49
  18. {google_auth-2.60.0 → google_auth-2.62.0}/tests/conftest.py +32 -0
  19. {google_auth-2.60.0 → google_auth-2.62.0}/tests/crypt/test__python_rsa.py +1 -1
  20. {google_auth-2.60.0 → google_auth-2.62.0}/tests/crypt/test_rsa.py +1 -1
  21. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_id_token.py +47 -10
  22. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_agent_identity_utils.py +442 -94
  23. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_identity_pool.py +32 -11
  24. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/aio/test_sessions_mtls.py +19 -7
  25. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/test__mtls_helper.py +336 -9
  26. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/test_mtls.py +88 -6
  27. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/test_requests.py +22 -9
  28. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/test_urllib3.py +21 -8
  29. {google_auth-2.60.0 → google_auth-2.62.0}/LICENSE +0 -0
  30. {google_auth-2.60.0 → google_auth-2.62.0}/MANIFEST.in +0 -0
  31. {google_auth-2.60.0 → google_auth-2.62.0}/README.rst +0 -0
  32. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/__init__.py +0 -0
  33. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_cache.py +0 -0
  34. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_cloud_sdk.py +0 -0
  35. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_credentials_async.py +0 -0
  36. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_credentials_base.py +0 -0
  37. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_default.py +0 -0
  38. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_default_async.py +0 -0
  39. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_exponential_backoff.py +0 -0
  40. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_helpers.py +0 -0
  41. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_jwt_async.py +0 -0
  42. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_oauth2client.py +0 -0
  43. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_refresh_worker.py +0 -0
  44. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_regional_access_boundary_utils.py +0 -0
  45. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/_service_account_info.py +0 -0
  46. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/aio/__init__.py +0 -0
  47. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/aio/_helpers.py +0 -0
  48. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/aio/credentials.py +0 -0
  49. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/aio/transport/__init__.py +0 -0
  50. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/aio/transport/aiohttp.py +0 -0
  51. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/aio/transport/mtls.py +0 -0
  52. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/api_key.py +0 -0
  53. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/app_engine.py +0 -0
  54. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/aws.py +0 -0
  55. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/compute_engine/__init__.py +0 -0
  56. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/compute_engine/_mtls.py +0 -0
  57. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/credentials.py +0 -0
  58. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/crypt/__init__.py +0 -0
  59. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/crypt/_cryptography_rsa.py +0 -0
  60. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/crypt/_helpers.py +0 -0
  61. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/crypt/_python_rsa.py +0 -0
  62. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/crypt/base.py +0 -0
  63. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/crypt/es.py +0 -0
  64. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/crypt/es256.py +0 -0
  65. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/crypt/rsa.py +0 -0
  66. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/downscoped.py +0 -0
  67. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/exceptions.py +0 -0
  68. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/external_account.py +0 -0
  69. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/external_account_authorized_user.py +0 -0
  70. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/iam.py +0 -0
  71. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/impersonated_credentials.py +0 -0
  72. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/jwt.py +0 -0
  73. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/metrics.py +0 -0
  74. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/pluggable.py +0 -0
  75. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/py.typed +0 -0
  76. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/transport/__init__.py +0 -0
  77. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/transport/_aiohttp_requests.py +0 -0
  78. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/transport/_custom_tls_signer.py +0 -0
  79. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/transport/_http_client.py +0 -0
  80. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/transport/_requests_base.py +0 -0
  81. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/transport/grpc.py +0 -0
  82. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/transport/requests.py +0 -0
  83. {google_auth-2.60.0 → google_auth-2.62.0}/google/auth/transport/urllib3.py +0 -0
  84. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/__init__.py +0 -0
  85. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/_client.py +0 -0
  86. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/_client_async.py +0 -0
  87. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/_credentials_async.py +0 -0
  88. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/_reauth_async.py +0 -0
  89. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/_service_account_async.py +0 -0
  90. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/challenges.py +0 -0
  91. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/credentials.py +0 -0
  92. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/gdch_credentials.py +0 -0
  93. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/py.typed +0 -0
  94. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/reauth.py +0 -0
  95. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/service_account.py +0 -0
  96. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/sts.py +0 -0
  97. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/utils.py +0 -0
  98. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/webauthn_handler.py +0 -0
  99. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/webauthn_handler_factory.py +0 -0
  100. {google_auth-2.60.0 → google_auth-2.62.0}/google/oauth2/webauthn_types.py +0 -0
  101. {google_auth-2.60.0 → google_auth-2.62.0}/google_auth.egg-info/SOURCES.txt +0 -0
  102. {google_auth-2.60.0 → google_auth-2.62.0}/google_auth.egg-info/dependency_links.txt +0 -0
  103. {google_auth-2.60.0 → google_auth-2.62.0}/google_auth.egg-info/top_level.txt +0 -0
  104. {google_auth-2.60.0 → google_auth-2.62.0}/setup.cfg +0 -0
  105. {google_auth-2.60.0 → google_auth-2.62.0}/tests/__init__.py +0 -0
  106. {google_auth-2.60.0 → google_auth-2.62.0}/tests/aio/test__helpers.py +0 -0
  107. {google_auth-2.60.0 → google_auth-2.62.0}/tests/compute_engine/__init__.py +0 -0
  108. {google_auth-2.60.0 → google_auth-2.62.0}/tests/compute_engine/data/smbios_product_name +0 -0
  109. {google_auth-2.60.0 → google_auth-2.62.0}/tests/compute_engine/data/smbios_product_name_non_google +0 -0
  110. {google_auth-2.60.0 → google_auth-2.62.0}/tests/compute_engine/test__mtls.py +0 -0
  111. {google_auth-2.60.0 → google_auth-2.62.0}/tests/crypt/__init__.py +0 -0
  112. {google_auth-2.60.0 → google_auth-2.62.0}/tests/crypt/test__cryptography_rsa.py +0 -0
  113. {google_auth-2.60.0 → google_auth-2.62.0}/tests/crypt/test_crypt.py +0 -0
  114. {google_auth-2.60.0 → google_auth-2.62.0}/tests/crypt/test_es.py +0 -0
  115. {google_auth-2.60.0 → google_auth-2.62.0}/tests/crypt/test_es256.py +0 -0
  116. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/authorized_user.json +0 -0
  117. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/authorized_user_cloud_sdk.json +0 -0
  118. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/authorized_user_cloud_sdk_with_quota_project_id.json +0 -0
  119. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/authorized_user_with_rapt_token.json +0 -0
  120. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/client_secrets.json +0 -0
  121. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/context_aware_metadata.json +0 -0
  122. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/enterprise_cert_invalid.json +0 -0
  123. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/enterprise_cert_valid.json +0 -0
  124. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/enterprise_cert_valid_provider.json +0 -0
  125. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/es256_privatekey.pem +0 -0
  126. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/es256_public_cert.pem +0 -0
  127. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/es256_publickey.pem +0 -0
  128. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/es256_service_account.json +0 -0
  129. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/es384_privatekey.pem +0 -0
  130. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/es384_public_cert.pem +0 -0
  131. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/es384_publickey.pem +0 -0
  132. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/es384_service_account.json +0 -0
  133. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/external_account_authorized_user.json +0 -0
  134. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/external_account_authorized_user_non_gdu.json +0 -0
  135. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/external_subject_token.json +0 -0
  136. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/external_subject_token.txt +0 -0
  137. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/gdch_service_account.json +0 -0
  138. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/impersonated_service_account_authorized_user_source.json +0 -0
  139. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/impersonated_service_account_external_account_authorized_user_source.json +0 -0
  140. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/impersonated_service_account_service_account_source.json +0 -0
  141. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/impersonated_service_account_with_quota_project.json +0 -0
  142. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/old_oauth_credentials_py3.pickle +0 -0
  143. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/other_cert.pem +0 -0
  144. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/pem_from_pkcs12.pem +0 -0
  145. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/privatekey.p12 +0 -0
  146. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/privatekey.pem +0 -0
  147. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/privatekey.pub +0 -0
  148. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/public_cert.pem +0 -0
  149. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/service_account.json +0 -0
  150. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/service_account_non_gdu.json +0 -0
  151. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/trust_chain_with_leaf.pem +0 -0
  152. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/trust_chain_without_leaf.pem +0 -0
  153. {google_auth-2.60.0 → google_auth-2.62.0}/tests/data/trust_chain_wrong_order.pem +0 -0
  154. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/__init__.py +0 -0
  155. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test__client.py +0 -0
  156. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_challenges.py +0 -0
  157. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_credentials.py +0 -0
  158. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_gdch_credentials.py +0 -0
  159. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_reauth.py +0 -0
  160. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_service_account.py +0 -0
  161. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_sts.py +0 -0
  162. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_utils.py +0 -0
  163. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_webauthn_handler.py +0 -0
  164. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_webauthn_handler_factory.py +0 -0
  165. {google_auth-2.60.0 → google_auth-2.62.0}/tests/oauth2/test_webauthn_types.py +0 -0
  166. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test__cache.py +0 -0
  167. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test__cloud_sdk.py +0 -0
  168. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test__default.py +0 -0
  169. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test__exponential_backoff.py +0 -0
  170. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test__helpers.py +0 -0
  171. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test__oauth2client.py +0 -0
  172. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test__refresh_worker.py +0 -0
  173. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test__regional_access_boundary_utils.py +0 -0
  174. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test__service_account_info.py +0 -0
  175. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_api_key.py +0 -0
  176. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_app_engine.py +0 -0
  177. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_aws.py +0 -0
  178. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_credentials.py +0 -0
  179. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_credentials_async.py +0 -0
  180. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_downscoped.py +0 -0
  181. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_exceptions.py +0 -0
  182. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_external_account.py +0 -0
  183. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_external_account_authorized_user.py +0 -0
  184. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_iam.py +0 -0
  185. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_impersonated_credentials.py +0 -0
  186. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_jwt.py +0 -0
  187. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_metrics.py +0 -0
  188. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_packaging.py +0 -0
  189. {google_auth-2.60.0 → google_auth-2.62.0}/tests/test_pluggable.py +0 -0
  190. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/__init__.py +0 -0
  191. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/aio/conftest.py +0 -0
  192. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/aio/test_aiohttp.py +0 -0
  193. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/aio/test_mtls.py +0 -0
  194. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/aio/test_sessions.py +0 -0
  195. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/aioresponses_compat.py +0 -0
  196. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/compliance.py +0 -0
  197. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/test__custom_tls_signer.py +0 -0
  198. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/test__http_client.py +0 -0
  199. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/test_aio_mtls_helper.py +0 -0
  200. {google_auth-2.60.0 → google_auth-2.62.0}/tests/transport/test_grpc.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-auth
3
- Version: 2.60.0
3
+ Version: 2.62.0
4
4
  Summary: Google Authentication Library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-auth
6
6
  Author: Google Cloud Platform
@@ -68,7 +68,6 @@ Provides-Extra: urllib3
68
68
  Requires-Dist: urllib3<3.0.0,>=1.26.15; extra == "urllib3"
69
69
  Requires-Dist: packaging>=20.0; extra == "urllib3"
70
70
  Provides-Extra: rsa
71
- Requires-Dist: rsa<5,>=4.0.0; extra == "rsa"
72
71
  Provides-Extra: grpc
73
72
  Requires-Dist: grpcio<2.0.0,>=1.59.0; python_version < "3.14" and extra == "grpc"
74
73
  Requires-Dist: grpcio<2.0.0,>=1.75.1; python_version >= "3.14" and extra == "grpc"
@@ -16,6 +16,7 @@
16
16
 
17
17
  import base64
18
18
  import hashlib
19
+ import json
19
20
  import os
20
21
  import re
21
22
  import stat
@@ -73,13 +74,32 @@ def _is_certificate_file_ready(path):
73
74
  return False
74
75
 
75
76
 
77
+ def _is_in_well_known_dir(path):
78
+ """Checks if the given path is inside the well-known Agent Identity directory."""
79
+ if not path:
80
+ return False
81
+ well_known_dir = os.path.dirname(_WELL_KNOWN_CERT_PATH)
82
+ try:
83
+ real_path = os.path.realpath(path)
84
+ real_well_known_dir = os.path.realpath(well_known_dir)
85
+ return (
86
+ os.path.commonpath([real_well_known_dir, real_path]) == real_well_known_dir
87
+ )
88
+ except ValueError:
89
+ return False
90
+
91
+
76
92
  def get_agent_identity_certificate_path():
77
- """Gets the agent certificate path from the certificate config file.
93
+ """Gets the agent certificate path from the certificate config file or GKE bundle.
78
94
 
79
95
  The path to the certificate config file is read from the
80
96
  GOOGLE_API_CERTIFICATE_CONFIG environment variable. This function
81
97
  can optionally trigger polling to handle cases where the environment
82
98
  variable is set before the files are available on the filesystem.
99
+ When GOOGLE_API_CERTIFICATE_CONFIG and
100
+ CLOUDSDK_CONTEXT_AWARE_CERTIFICATE_CONFIG_FILE_PATH are unset and no
101
+ implicit certificate_config.json is present, it falls back to checking
102
+ the GKE workload credential bundle path without polling.
83
103
 
84
104
  Returns:
85
105
  Optional[str]: The path to the agent's certificate file, or None if unavailable.
@@ -88,9 +108,18 @@ def get_agent_identity_certificate_path():
88
108
  google.auth.exceptions.RefreshError: If the certificate config file
89
109
  or the certificate file cannot be found after retries.
90
110
  """
111
+ from google.auth.transport import _mtls_helper
112
+
91
113
  cert_config_path = os.environ.get(environment_vars.GOOGLE_API_CERTIFICATE_CONFIG)
92
114
 
93
115
  if not cert_config_path:
116
+ if (
117
+ not _mtls_helper._has_explicit_cert_config_env()
118
+ and _mtls_helper._should_use_gke_credential_bundle(
119
+ _mtls_helper._get_cert_config_path()
120
+ )
121
+ ):
122
+ return _mtls_helper._GKE_CREDENTIAL_BUNDLE_PATH
94
123
  return None
95
124
 
96
125
  # We trigger polling only if the config path points to the well-known directory.
@@ -98,16 +127,7 @@ def get_agent_identity_certificate_path():
98
127
  # config file and the certificate file may experience a brief startup latency.
99
128
  # For all other paths, we return early to avoid introducing unnecessary startup
100
129
  # delays.
101
- well_known_dir = os.path.dirname(_WELL_KNOWN_CERT_PATH)
102
- try:
103
- abs_cert_path = os.path.abspath(cert_config_path)
104
- abs_well_known_dir = os.path.abspath(well_known_dir)
105
- should_poll = (
106
- os.path.commonpath([abs_well_known_dir, abs_cert_path])
107
- == abs_well_known_dir
108
- )
109
- except ValueError:
110
- should_poll = False
130
+ should_poll = _is_in_well_known_dir(cert_config_path)
111
131
 
112
132
  return _get_cert_path_with_optional_polling(cert_config_path, should_poll)
113
133
 
@@ -141,9 +161,9 @@ def _get_cert_path_with_optional_polling(cert_config_path, should_poll):
141
161
  if _is_certificate_file_ready(cert_path):
142
162
  return cert_path
143
163
 
144
- # The config was parsed, but the cert file is not ready yet
145
- if not should_poll:
146
- # If polling is disabled, return early.
164
+ # The config was parsed, but the cert file is not ready yet.
165
+ # Only poll if both the config path and cert path are in the well-known directory.
166
+ if not (should_poll and _is_in_well_known_dir(cert_path)):
147
167
  return None
148
168
 
149
169
  if not has_logged_cert_warning:
@@ -182,7 +202,7 @@ def _get_cert_path_with_optional_polling(cert_config_path, should_poll):
182
202
  raise exceptions.RefreshError(
183
203
  "Certificate config or certificate file not found after multiple retries. "
184
204
  f"Token binding protection is failing. You can turn off this protection by setting "
185
- f"{environment_vars.GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES} to false "
205
+ f"{environment_vars.GOOGLE_API_ENABLE_RUNTIME_BOUND_TOKEN} to false "
186
206
  "to fall back to unbound tokens."
187
207
  )
188
208
 
@@ -203,8 +223,6 @@ def _parse_cert_path_from_config(cert_config_path):
203
223
  KeyError: If the certificate config file does not contain the
204
224
  expected structure.
205
225
  """
206
- import json
207
-
208
226
  with open(cert_config_path, "r", encoding="utf-8") as f:
209
227
  cert_config = json.load(f)
210
228
 
@@ -221,64 +239,105 @@ def _parse_cert_path_from_config(cert_config_path):
221
239
  return workload_config["cert_path"]
222
240
 
223
241
 
224
- def get_and_parse_agent_identity_certificate():
242
+ def _is_bound_token_opted_out():
243
+ """Returns True only if bound tokens are explicitly disabled via env vars."""
244
+ val = os.environ.get(
245
+ environment_vars.GOOGLE_API_ENABLE_RUNTIME_BOUND_TOKEN, ""
246
+ ).strip()
247
+ if not val:
248
+ # Fall back to the deprecated env var for backward compatibility
249
+ val = os.environ.get(
250
+ environment_vars.GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES,
251
+ "true",
252
+ ).strip()
253
+ return val.lower() == "false"
254
+
255
+
256
+ def get_agent_identity_certificate_and_bytes():
225
257
  """Gets and parses the agent identity certificate if not opted out.
226
258
 
227
259
  Checks if the user has opted out of certificate-bound tokens. If not,
228
260
  it gets the certificate path, reads the file, and parses it.
229
261
 
230
262
  Returns:
231
- The parsed certificate object if found and not opted out, otherwise None.
263
+ Tuple[Optional[cryptography.x509.Certificate], Optional[bytes]]: A tuple
264
+ of (parsed certificate object, certificate bytes) if found and not
265
+ opted out, otherwise (None, None).
232
266
  """
267
+ from google.auth.transport import _mtls_helper
268
+
233
269
  # If the user has opted out of cert bound tokens, there is no need to
234
270
  # look up the certificate.
235
- is_opted_out = (
236
- os.environ.get(
237
- environment_vars.GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES,
238
- "true",
239
- ).lower()
240
- == "false"
241
- )
242
- if is_opted_out:
243
- return None
271
+ if _is_bound_token_opted_out():
272
+ return None, None
244
273
 
245
274
  # Respect explicit opt-out of mTLS / client certs
246
- from google.auth.transport import _mtls_helper
247
-
248
275
  env_override = _mtls_helper._check_use_client_cert_env()
249
276
  if env_override is False:
250
- return None
277
+ return None, None
251
278
 
252
279
  cert_path = get_agent_identity_certificate_path()
253
280
  if not cert_path:
254
- return None
281
+ return None, None
255
282
 
256
283
  try:
257
284
  with open(cert_path, "rb") as cert_file:
258
- cert_bytes = cert_file.read()
259
- except PermissionError as e:
285
+ raw_bytes = cert_file.read()
286
+ except OSError as e:
260
287
  warnings.warn(
261
288
  f"Failed to read agent identity certificate file at {cert_path}: {e}. "
262
289
  "Token binding protection cannot be enabled. Falling back to unbound tokens."
263
290
  )
264
- return None
291
+ return None, None
265
292
 
266
- return parse_certificate(cert_bytes)
293
+ cert_blocks = _mtls_helper._CERT_REGEX.findall(raw_bytes)
294
+ if not cert_blocks:
295
+ warnings.warn(
296
+ f"No PEM certificate blocks found in {cert_path}. "
297
+ "Token binding protection cannot be enabled. Falling back to unbound tokens."
298
+ )
299
+ return None, None
300
+
301
+ cert_bytes = b"\n".join(block.strip() for block in cert_blocks) + b"\n"
302
+ try:
303
+ return parse_certificate(raw_bytes), cert_bytes
304
+ except (ValueError, ImportError) as e:
305
+ warnings.warn(
306
+ f"Failed to parse agent identity certificate at {cert_path}: {e}. "
307
+ "Token binding protection cannot be enabled. Falling back to unbound tokens."
308
+ )
309
+ return None, None
267
310
 
268
311
 
269
312
  def parse_certificate(cert_bytes):
270
- """Parses a PEM-encoded certificate.
313
+ """Parses a PEM-encoded certificate or certificate chain and returns the leaf certificate.
271
314
 
272
315
  Args:
273
316
  cert_bytes (bytes): The PEM-encoded certificate bytes.
274
317
 
275
318
  Returns:
276
- cryptography.x509.Certificate: The parsed certificate object.
319
+ cryptography.x509.Certificate: The leaf (first) parsed certificate object.
320
+
321
+ Raises:
322
+ ValueError: If no certificates are found or any certificate in the chain
323
+ is malformed.
324
+ ImportError: If the cryptography library is not installed.
277
325
  """
326
+ from google.auth.transport import _mtls_helper
327
+
328
+ if not cert_bytes:
329
+ raise ValueError("Certificate bytes cannot be empty or None.")
330
+
278
331
  try:
279
332
  from cryptography import x509
280
333
 
281
- return x509.load_pem_x509_certificate(cert_bytes)
334
+ cert_blocks = _mtls_helper._CERT_REGEX.findall(cert_bytes)
335
+ if not cert_blocks:
336
+ return x509.load_pem_x509_certificate(cert_bytes)
337
+ if _mtls_helper._has_unmatched_pem_markers(cert_bytes, cert_blocks):
338
+ raise ValueError("Malformed or truncated PEM certificate chain.")
339
+ certs = [x509.load_pem_x509_certificate(block) for block in cert_blocks]
340
+ return certs[0]
282
341
  except ImportError as e:
283
342
  raise ImportError(CRYPTOGRAPHY_NOT_FOUND_ERROR) from e
284
343
 
@@ -350,8 +409,9 @@ def calculate_certificate_fingerprint(cert):
350
409
  def should_request_bound_token(cert):
351
410
  """Determines if a bound token should be requested.
352
411
 
353
- This is based on the GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES
354
- environment variable and whether the certificate is an agent identity cert.
412
+ This is based on the GOOGLE_API_ENABLE_RUNTIME_BOUND_TOKEN env var
413
+ (falls back to the deprecated GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES
414
+ if unset or empty) and whether the certificate is an agent identity cert.
355
415
 
356
416
  Args:
357
417
  cert (cryptography.x509.Certificate): The parsed certificate object.
@@ -359,25 +419,17 @@ def should_request_bound_token(cert):
359
419
  Returns:
360
420
  bool: True if a bound token should be requested, False otherwise.
361
421
  """
362
- is_agent_cert = _is_agent_identity_certificate(cert)
363
- is_opted_in = (
364
- os.environ.get(
365
- environment_vars.GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES,
366
- "true",
367
- ).lower()
368
- == "true"
369
- )
370
- if not (is_agent_cert and is_opted_in):
422
+ from google.auth.transport import _mtls_helper
423
+
424
+ if _is_bound_token_opted_out():
371
425
  return False
372
426
 
373
427
  # Respect explicit opt-out of mTLS / client certs
374
- from google.auth.transport import _mtls_helper
375
-
376
428
  env_override = _mtls_helper._check_use_client_cert_env()
377
429
  if env_override is False:
378
430
  return False
379
431
 
380
- return True
432
+ return _is_agent_identity_certificate(cert)
381
433
 
382
434
 
383
435
  def get_cached_cert_fingerprint(cached_cert):
@@ -19,7 +19,6 @@ import http.client as http_client
19
19
  import inspect
20
20
  import logging
21
21
  import time
22
- import urllib.parse
23
22
  import warnings
24
23
  from contextlib import asynccontextmanager
25
24
  from typing import TYPE_CHECKING, Mapping, Optional, Union
@@ -44,11 +43,6 @@ else:
44
43
  ClientTimeout = None
45
44
 
46
45
  _LOGGER = logging.getLogger(__name__)
47
- _MTLS_URL_PREFIXES = [
48
- "mtls.googleapis.com",
49
- "mtls.sandbox.googleapis.com",
50
- "p.googleapis.com",
51
- ]
52
46
 
53
47
  # Tracks the internal aiohttp installation and usage
54
48
  try:
@@ -482,13 +476,9 @@ class AsyncAuthorizedSession:
482
476
  async def _recover_auth_state():
483
477
  is_mtls_endpoint = False
484
478
  if self._is_mtls:
485
- hostname = urllib.parse.urlsplit(url).hostname
486
- if hostname:
487
- is_mtls_endpoint = any(
488
- hostname == prefix
489
- or hostname.endswith("." + prefix)
490
- for prefix in _MTLS_URL_PREFIXES
491
- )
479
+ is_mtls_endpoint = (
480
+ google.auth.transport._mtls_helper.is_mtls_endpoint(url)
481
+ )
492
482
  # Snapshot the stale certificate state BEFORE acquiring the lock.
493
483
  # This represents the cert that caused the 401 rejection.
494
484
  if is_mtls_endpoint:
@@ -27,7 +27,14 @@ from urllib.parse import urljoin
27
27
 
28
28
  import requests
29
29
 
30
- from google.auth import _helpers, environment_vars, exceptions, metrics, transport
30
+ from google.auth import (
31
+ _agent_identity_utils,
32
+ _helpers,
33
+ environment_vars,
34
+ exceptions,
35
+ metrics,
36
+ transport,
37
+ )
31
38
  from google.auth._exponential_backoff import ExponentialBackoff
32
39
  from google.auth.compute_engine import _mtls
33
40
 
@@ -250,6 +257,8 @@ def get(
250
257
  headers=None,
251
258
  return_none_for_not_found_error=False,
252
259
  timeout=_METADATA_DEFAULT_TIMEOUT,
260
+ method="GET",
261
+ body=None,
253
262
  ):
254
263
  """Fetch a resource from the metadata server.
255
264
 
@@ -271,6 +280,8 @@ def get(
271
280
  return_none_for_not_found_error (Optional[bool]): If True, returns None
272
281
  for 404 error instead of throwing an exception.
273
282
  timeout (int): How long to wait, in seconds for the metadata server to respond.
283
+ method (str): The HTTP method to use for the request. Defaults to "GET".
284
+ body (Optional[bytes]): The HTTP request body payload to send. Defaults to None.
274
285
 
275
286
  Returns:
276
287
  Union[Mapping, str]: If the metadata server returns JSON, a mapping of
@@ -283,8 +294,12 @@ def get(
283
294
  google.auth.exceptions.MutualTLSChannelError: if using mtls and the environment
284
295
  configuration is invalid for mTLS (for example, the metadata host
285
296
  has been overridden in strict mTLS mode).
297
+ ValueError: if a request body is specified with the GET method.
286
298
 
287
299
  """
300
+ if body is not None and method.upper() == "GET":
301
+ raise ValueError("Request body cannot be specified with GET method.")
302
+
288
303
  use_mtls = _mtls.should_use_mds_mtls()
289
304
  # Prepare the request object for mTLS if needed.
290
305
  # This will create a new request object with the mTLS session.
@@ -314,9 +329,15 @@ def get(
314
329
  last_exception = None
315
330
  for attempt in backoff:
316
331
  try:
317
- response = request(
318
- url=url, method="GET", headers=headers_to_use, timeout=timeout
319
- )
332
+ kwargs = {
333
+ "url": url,
334
+ "method": method,
335
+ "headers": headers_to_use,
336
+ "timeout": timeout,
337
+ }
338
+ if body is not None:
339
+ kwargs["body"] = body
340
+ response = request(**kwargs)
320
341
  if response.status in transport.DEFAULT_RETRYABLE_STATUS_CODES:
321
342
  _LOGGER.warning(
322
343
  "Compute Engine Metadata server unavailable on "
@@ -460,6 +481,40 @@ def get_service_account_info(request, service_account="default"):
460
481
  return get(request, path, params={"recursive": "true"})
461
482
 
462
483
 
484
+ def _build_token_request_options(metrics_header_value, bind_token=True):
485
+ """Returns (method, body, headers) for a metadata server token request.
486
+
487
+ Defaults to a standard GET request with the x-goog-api-client metrics header.
488
+ If ``bind_token`` is ``True``, upgrades to a POST request with a JSON
489
+ certificate_chain body and Content-Type header if an Agent Identity
490
+ certificate is present and bound tokens are enabled.
491
+
492
+ Args:
493
+ metrics_header_value (str): Value for the x-goog-api-client header.
494
+ bind_token (bool): Whether to bind the token to the Agent Identity
495
+ certificate. Defaults to ``True``. If ``False``, returns a ``GET``
496
+ request without reading the certificate. If ``True``, requests a
497
+ bound token via ``POST`` when a valid Agent Identity certificate is
498
+ present and token binding is enabled.
499
+
500
+ Returns:
501
+ Tuple[str, Optional[bytes], Mapping[str, str]]: A tuple of
502
+ (HTTP method, request body bytes, request headers).
503
+ """
504
+ headers = {metrics.API_CLIENT_HEADER: metrics_header_value}
505
+ if not bind_token:
506
+ return "GET", None, headers
507
+
508
+ cert, cert_bytes = _agent_identity_utils.get_agent_identity_certificate_and_bytes()
509
+ if cert and _agent_identity_utils.should_request_bound_token(cert):
510
+ headers["Content-Type"] = "application/json"
511
+ body = json.dumps({"certificate_chain": cert_bytes.decode("utf-8")}).encode(
512
+ "utf-8"
513
+ )
514
+ return "POST", body, headers
515
+ return "GET", None, headers
516
+
517
+
463
518
  def get_service_account_token(request, service_account="default", scopes=None):
464
519
  """Get the OAuth 2.0 access token for a service account.
465
520
 
@@ -478,26 +533,20 @@ def get_service_account_token(request, service_account="default", scopes=None):
478
533
  google.auth.exceptions.TransportError: if an error occurred while
479
534
  retrieving metadata.
480
535
  """
481
- from google.auth import _agent_identity_utils
482
-
483
536
  params = {}
484
537
  if scopes:
485
538
  if not isinstance(scopes, str):
486
539
  scopes = ",".join(scopes)
487
540
  params["scopes"] = scopes
488
541
 
489
- cert = _agent_identity_utils.get_and_parse_agent_identity_certificate()
490
- if cert:
491
- if _agent_identity_utils.should_request_bound_token(cert):
492
- fingerprint = _agent_identity_utils.calculate_certificate_fingerprint(cert)
493
- params["bindCertificateFingerprint"] = fingerprint
494
-
495
- metrics_header = {
496
- metrics.API_CLIENT_HEADER: metrics.token_request_access_token_mds()
497
- }
542
+ method, body, headers = _build_token_request_options(
543
+ metrics.token_request_access_token_mds()
544
+ )
498
545
 
499
546
  path = "instance/service-accounts/{0}/token".format(service_account)
500
- token_json = get(request, path, params=params, headers=metrics_header)
547
+ token_json = get(
548
+ request, path, params=params, headers=headers, method=method, body=body
549
+ )
501
550
  token_expiry = _helpers.utcnow() + datetime.timedelta(
502
551
  seconds=token_json["expires_in"]
503
552
  )
@@ -340,6 +340,7 @@ class IDTokenCredentials(
340
340
  signer=None,
341
341
  use_metadata_identity_endpoint=False,
342
342
  quota_project_id=None,
343
+ bind_id_token=None,
343
344
  ):
344
345
  """
345
346
  Args:
@@ -364,18 +365,34 @@ class IDTokenCredentials(
364
365
  otherwise ValueError will be raised.
365
366
  quota_project_id (Optional[str]): The project ID used for quota and
366
367
  billing.
368
+ bind_id_token (Optional[bool]): Controls whether to request a
369
+ certificate-bound ID token. Can only be set when
370
+ ``use_metadata_identity_endpoint`` is ``True``.
371
+ If ``True``, requests a bound token whenever a valid Agent
372
+ Identity certificate is available and token binding is not
373
+ disabled via ``GOOGLE_API_ENABLE_RUNTIME_BOUND_TOKEN``, falling
374
+ back to an unbound token otherwise (or raising
375
+ :class:`~google.auth.exceptions.RefreshError` if a configured
376
+ certificate is not found after retries). If ``False``, always
377
+ requests an unbound token. If ``None`` (default), token binding
378
+ is determined automatically by the library. Set ``True`` or
379
+ ``False`` explicitly if your application requires a specific
380
+ behavior.
367
381
 
368
382
  Raises:
369
383
  ValueError:
370
384
  If ``use_metadata_identity_endpoint`` is set to True, and one of
371
385
  ``token_uri``, ``additional_claims``, ``service_account_email``,
372
- ``signer`` arguments is set.
386
+ ``signer`` arguments is set, or if
387
+ ``use_metadata_identity_endpoint`` is False and
388
+ ``bind_id_token`` is not None.
373
389
  """
374
390
  super(IDTokenCredentials, self).__init__()
375
391
 
376
392
  self._quota_project_id = quota_project_id
377
393
  self._use_metadata_identity_endpoint = use_metadata_identity_endpoint
378
394
  self._target_audience = target_audience
395
+ self._bind_id_token = bind_id_token
379
396
 
380
397
  if use_metadata_identity_endpoint:
381
398
  if token_uri or additional_claims or service_account_email or signer:
@@ -387,8 +404,13 @@ class IDTokenCredentials(
387
404
  self._token_uri = None
388
405
  self._additional_claims = None
389
406
  self._signer = None
407
+ elif bind_id_token is not None:
408
+ raise ValueError(
409
+ "If use_metadata_identity_endpoint is False, bind_id_token "
410
+ "must not be set"
411
+ )
390
412
 
391
- if service_account_email is None:
413
+ if service_account_email is None and request is not None:
392
414
  sa_info = _metadata.get_service_account_info(request)
393
415
  self._service_account_email = sa_info["email"]
394
416
  else:
@@ -409,79 +431,60 @@ class IDTokenCredentials(
409
431
  else:
410
432
  self._additional_claims = {}
411
433
 
412
- def with_target_audience(self, target_audience):
413
- """Create a copy of these credentials with the specified target
414
- audience.
415
- Args:
416
- target_audience (str): The intended audience for these credentials,
417
- used when requesting the ID Token.
418
- Returns:
419
- google.auth.service_account.IDTokenCredentials: A new credentials
420
- instance.
421
- """
434
+ def _make_copy(self):
422
435
  # since the signer is already instantiated,
423
436
  # the request is not needed
424
437
  if self._use_metadata_identity_endpoint:
425
- return self.__class__(
438
+ cred = self.__class__(
426
439
  None,
427
- target_audience=target_audience,
440
+ target_audience=self._target_audience,
428
441
  use_metadata_identity_endpoint=True,
429
442
  quota_project_id=self._quota_project_id,
430
443
  )
444
+ cred._service_account_email = self._service_account_email
445
+ cred._bind_id_token = getattr(self, "_bind_id_token", None)
446
+ return cred
431
447
  else:
432
448
  return self.__class__(
433
449
  None,
434
450
  service_account_email=self._service_account_email,
435
451
  token_uri=self._token_uri,
436
- target_audience=target_audience,
452
+ target_audience=self._target_audience,
437
453
  additional_claims=self._additional_claims.copy(),
438
454
  signer=self.signer,
439
455
  use_metadata_identity_endpoint=False,
440
456
  quota_project_id=self._quota_project_id,
441
457
  )
442
458
 
459
+ def with_target_audience(self, target_audience):
460
+ """Create a copy of these credentials with the specified target
461
+ audience.
462
+ Args:
463
+ target_audience (str): The intended audience for these credentials,
464
+ used when requesting the ID Token.
465
+ Returns:
466
+ google.auth.service_account.IDTokenCredentials: A new credentials
467
+ instance.
468
+ """
469
+ cred = self._make_copy()
470
+ cred._target_audience = target_audience
471
+ return cred
472
+
443
473
  @_helpers.copy_docstring(credentials.CredentialsWithQuotaProject)
444
474
  def with_quota_project(self, quota_project_id):
445
- # since the signer is already instantiated,
446
- # the request is not needed
447
- if self._use_metadata_identity_endpoint:
448
- return self.__class__(
449
- None,
450
- target_audience=self._target_audience,
451
- use_metadata_identity_endpoint=True,
452
- quota_project_id=quota_project_id,
453
- )
454
- else:
455
- return self.__class__(
456
- None,
457
- service_account_email=self._service_account_email,
458
- token_uri=self._token_uri,
459
- target_audience=self._target_audience,
460
- additional_claims=self._additional_claims.copy(),
461
- signer=self.signer,
462
- use_metadata_identity_endpoint=False,
463
- quota_project_id=quota_project_id,
464
- )
475
+ cred = self._make_copy()
476
+ cred._quota_project_id = quota_project_id
477
+ return cred
465
478
 
466
479
  @_helpers.copy_docstring(credentials.CredentialsWithTokenUri)
467
480
  def with_token_uri(self, token_uri):
468
- # since the signer is already instantiated,
469
- # the request is not needed
470
481
  if self._use_metadata_identity_endpoint:
471
482
  raise ValueError(
472
483
  "If use_metadata_identity_endpoint is set, token_uri must not be set"
473
484
  )
474
- else:
475
- return self.__class__(
476
- None,
477
- service_account_email=self._service_account_email,
478
- token_uri=token_uri,
479
- target_audience=self._target_audience,
480
- additional_claims=self._additional_claims.copy(),
481
- signer=self.signer,
482
- use_metadata_identity_endpoint=False,
483
- quota_project_id=self.quota_project_id,
484
- )
485
+ cred = self._make_copy()
486
+ cred._token_uri = token_uri
487
+ return cred
485
488
 
486
489
  def _make_authorization_grant_assertion(self):
487
490
  """Create the OAuth 2.0 assertion.
@@ -530,11 +533,19 @@ class IDTokenCredentials(
530
533
  try:
531
534
  path = "instance/service-accounts/default/identity"
532
535
  params = {"audience": self._target_audience, "format": "full"}
533
- metrics_header = {
534
- metrics.API_CLIENT_HEADER: metrics.token_request_id_token_mds()
535
- }
536
+ bind_token = getattr(self, "_bind_id_token", None) is not False
537
+ method, body, headers = _metadata._build_token_request_options(
538
+ metrics.token_request_id_token_mds(),
539
+ bind_token=bind_token,
540
+ )
541
+
536
542
  id_token = _metadata.get(
537
- request, path, params=params, headers=metrics_header
543
+ request,
544
+ path,
545
+ params=params,
546
+ headers=headers,
547
+ method=method,
548
+ body=body,
538
549
  )
539
550
  except exceptions.TransportError as caught_exc:
540
551
  new_exc = exceptions.RefreshError(caught_exc)
@@ -128,10 +128,22 @@ CLOUDSDK_CONTEXT_AWARE_CERTIFICATE_CONFIG_FILE_PATH = (
128
128
  """Environment variable defining the location of Google API certificate config
129
129
  file. This variable is the fallback of GOOGLE_API_CERTIFICATE_CONFIG."""
130
130
 
131
+ GOOGLE_API_ENABLE_RUNTIME_BOUND_TOKEN = "GOOGLE_API_ENABLE_RUNTIME_BOUND_TOKEN"
132
+ """Environment variable controlling whether to enable runtime bound tokens.
133
+
134
+ Defaults to enabled; only a case-insensitive ``"false"`` disables it. When set
135
+ to a non-empty value, this variable takes precedence over
136
+ :data:`GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES`.
137
+ """
138
+
131
139
  GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES = (
132
140
  "GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES"
133
141
  )
134
- """Environment variable to prevent agent token sharing for GCP services."""
142
+ """Environment variable to prevent agent token sharing for GCP services.
143
+
144
+ .. deprecated:: v2.59.0
145
+ Use :data:`GOOGLE_API_ENABLE_RUNTIME_BOUND_TOKEN` instead.
146
+ """
135
147
 
136
148
  GOOGLE_API_USE_MTLS_ENDPOINT = "GOOGLE_API_USE_MTLS_ENDPOINT"
137
149
  """Environment variable controlling whether to use mTLS endpoint or not."""