google-auth 2.59.1__tar.gz → 2.60.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.59.1/google_auth.egg-info → google_auth-2.60.0}/PKG-INFO +1 -1
  2. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/aio/transport/sessions.py +117 -8
  3. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/version.py +1 -1
  4. {google_auth-2.59.1 → google_auth-2.60.0/google_auth.egg-info}/PKG-INFO +1 -1
  5. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/aio/test_sessions.py +257 -4
  6. {google_auth-2.59.1 → google_auth-2.60.0}/LICENSE +0 -0
  7. {google_auth-2.59.1 → google_auth-2.60.0}/MANIFEST.in +0 -0
  8. {google_auth-2.59.1 → google_auth-2.60.0}/README.rst +0 -0
  9. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/__init__.py +0 -0
  10. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_agent_identity_utils.py +0 -0
  11. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_cache.py +0 -0
  12. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_cloud_sdk.py +0 -0
  13. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_credentials_async.py +0 -0
  14. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_credentials_base.py +0 -0
  15. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_default.py +0 -0
  16. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_default_async.py +0 -0
  17. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_exponential_backoff.py +0 -0
  18. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_helpers.py +0 -0
  19. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_jwt_async.py +0 -0
  20. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_oauth2client.py +0 -0
  21. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_refresh_worker.py +0 -0
  22. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_regional_access_boundary_utils.py +0 -0
  23. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/_service_account_info.py +0 -0
  24. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/aio/__init__.py +0 -0
  25. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/aio/_helpers.py +0 -0
  26. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/aio/credentials.py +0 -0
  27. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/aio/transport/__init__.py +0 -0
  28. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/aio/transport/aiohttp.py +0 -0
  29. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/aio/transport/mtls.py +0 -0
  30. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/api_key.py +0 -0
  31. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/app_engine.py +0 -0
  32. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/aws.py +0 -0
  33. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/compute_engine/__init__.py +0 -0
  34. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/compute_engine/_metadata.py +0 -0
  35. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/compute_engine/_mtls.py +0 -0
  36. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/compute_engine/credentials.py +0 -0
  37. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/credentials.py +0 -0
  38. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/crypt/__init__.py +0 -0
  39. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/crypt/_cryptography_rsa.py +0 -0
  40. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/crypt/_helpers.py +0 -0
  41. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/crypt/_python_rsa.py +0 -0
  42. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/crypt/base.py +0 -0
  43. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/crypt/es.py +0 -0
  44. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/crypt/es256.py +0 -0
  45. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/crypt/rsa.py +0 -0
  46. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/downscoped.py +0 -0
  47. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/environment_vars.py +0 -0
  48. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/exceptions.py +0 -0
  49. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/external_account.py +0 -0
  50. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/external_account_authorized_user.py +0 -0
  51. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/iam.py +0 -0
  52. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/identity_pool.py +0 -0
  53. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/impersonated_credentials.py +0 -0
  54. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/jwt.py +0 -0
  55. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/metrics.py +0 -0
  56. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/pluggable.py +0 -0
  57. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/py.typed +0 -0
  58. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/transport/__init__.py +0 -0
  59. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/transport/_aiohttp_requests.py +0 -0
  60. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/transport/_custom_tls_signer.py +0 -0
  61. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/transport/_http_client.py +0 -0
  62. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/transport/_mtls_helper.py +0 -0
  63. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/transport/_requests_base.py +0 -0
  64. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/transport/grpc.py +0 -0
  65. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/transport/mtls.py +0 -0
  66. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/transport/requests.py +0 -0
  67. {google_auth-2.59.1 → google_auth-2.60.0}/google/auth/transport/urllib3.py +0 -0
  68. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/__init__.py +0 -0
  69. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/_client.py +0 -0
  70. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/_client_async.py +0 -0
  71. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/_credentials_async.py +0 -0
  72. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/_id_token_async.py +0 -0
  73. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/_reauth_async.py +0 -0
  74. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/_service_account_async.py +0 -0
  75. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/challenges.py +0 -0
  76. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/credentials.py +0 -0
  77. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/gdch_credentials.py +0 -0
  78. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/id_token.py +0 -0
  79. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/py.typed +0 -0
  80. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/reauth.py +0 -0
  81. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/service_account.py +0 -0
  82. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/sts.py +0 -0
  83. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/utils.py +0 -0
  84. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/webauthn_handler.py +0 -0
  85. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/webauthn_handler_factory.py +0 -0
  86. {google_auth-2.59.1 → google_auth-2.60.0}/google/oauth2/webauthn_types.py +0 -0
  87. {google_auth-2.59.1 → google_auth-2.60.0}/google_auth.egg-info/SOURCES.txt +0 -0
  88. {google_auth-2.59.1 → google_auth-2.60.0}/google_auth.egg-info/dependency_links.txt +0 -0
  89. {google_auth-2.59.1 → google_auth-2.60.0}/google_auth.egg-info/requires.txt +0 -0
  90. {google_auth-2.59.1 → google_auth-2.60.0}/google_auth.egg-info/top_level.txt +0 -0
  91. {google_auth-2.59.1 → google_auth-2.60.0}/setup.cfg +0 -0
  92. {google_auth-2.59.1 → google_auth-2.60.0}/setup.py +0 -0
  93. {google_auth-2.59.1 → google_auth-2.60.0}/tests/__init__.py +0 -0
  94. {google_auth-2.59.1 → google_auth-2.60.0}/tests/aio/test__helpers.py +0 -0
  95. {google_auth-2.59.1 → google_auth-2.60.0}/tests/compute_engine/__init__.py +0 -0
  96. {google_auth-2.59.1 → google_auth-2.60.0}/tests/compute_engine/data/smbios_product_name +0 -0
  97. {google_auth-2.59.1 → google_auth-2.60.0}/tests/compute_engine/data/smbios_product_name_non_google +0 -0
  98. {google_auth-2.59.1 → google_auth-2.60.0}/tests/compute_engine/test__metadata.py +0 -0
  99. {google_auth-2.59.1 → google_auth-2.60.0}/tests/compute_engine/test__mtls.py +0 -0
  100. {google_auth-2.59.1 → google_auth-2.60.0}/tests/compute_engine/test_credentials.py +0 -0
  101. {google_auth-2.59.1 → google_auth-2.60.0}/tests/conftest.py +0 -0
  102. {google_auth-2.59.1 → google_auth-2.60.0}/tests/crypt/__init__.py +0 -0
  103. {google_auth-2.59.1 → google_auth-2.60.0}/tests/crypt/test__cryptography_rsa.py +0 -0
  104. {google_auth-2.59.1 → google_auth-2.60.0}/tests/crypt/test__python_rsa.py +0 -0
  105. {google_auth-2.59.1 → google_auth-2.60.0}/tests/crypt/test_crypt.py +0 -0
  106. {google_auth-2.59.1 → google_auth-2.60.0}/tests/crypt/test_es.py +0 -0
  107. {google_auth-2.59.1 → google_auth-2.60.0}/tests/crypt/test_es256.py +0 -0
  108. {google_auth-2.59.1 → google_auth-2.60.0}/tests/crypt/test_rsa.py +0 -0
  109. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/authorized_user.json +0 -0
  110. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/authorized_user_cloud_sdk.json +0 -0
  111. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/authorized_user_cloud_sdk_with_quota_project_id.json +0 -0
  112. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/authorized_user_with_rapt_token.json +0 -0
  113. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/client_secrets.json +0 -0
  114. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/context_aware_metadata.json +0 -0
  115. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/enterprise_cert_invalid.json +0 -0
  116. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/enterprise_cert_valid.json +0 -0
  117. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/enterprise_cert_valid_provider.json +0 -0
  118. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/es256_privatekey.pem +0 -0
  119. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/es256_public_cert.pem +0 -0
  120. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/es256_publickey.pem +0 -0
  121. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/es256_service_account.json +0 -0
  122. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/es384_privatekey.pem +0 -0
  123. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/es384_public_cert.pem +0 -0
  124. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/es384_publickey.pem +0 -0
  125. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/es384_service_account.json +0 -0
  126. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/external_account_authorized_user.json +0 -0
  127. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/external_account_authorized_user_non_gdu.json +0 -0
  128. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/external_subject_token.json +0 -0
  129. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/external_subject_token.txt +0 -0
  130. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/gdch_service_account.json +0 -0
  131. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/impersonated_service_account_authorized_user_source.json +0 -0
  132. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/impersonated_service_account_external_account_authorized_user_source.json +0 -0
  133. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/impersonated_service_account_service_account_source.json +0 -0
  134. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/impersonated_service_account_with_quota_project.json +0 -0
  135. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/old_oauth_credentials_py3.pickle +0 -0
  136. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/other_cert.pem +0 -0
  137. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/pem_from_pkcs12.pem +0 -0
  138. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/privatekey.p12 +0 -0
  139. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/privatekey.pem +0 -0
  140. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/privatekey.pub +0 -0
  141. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/public_cert.pem +0 -0
  142. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/service_account.json +0 -0
  143. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/service_account_non_gdu.json +0 -0
  144. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/trust_chain_with_leaf.pem +0 -0
  145. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/trust_chain_without_leaf.pem +0 -0
  146. {google_auth-2.59.1 → google_auth-2.60.0}/tests/data/trust_chain_wrong_order.pem +0 -0
  147. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/__init__.py +0 -0
  148. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test__client.py +0 -0
  149. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_challenges.py +0 -0
  150. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_credentials.py +0 -0
  151. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_gdch_credentials.py +0 -0
  152. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_id_token.py +0 -0
  153. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_reauth.py +0 -0
  154. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_service_account.py +0 -0
  155. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_sts.py +0 -0
  156. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_utils.py +0 -0
  157. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_webauthn_handler.py +0 -0
  158. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_webauthn_handler_factory.py +0 -0
  159. {google_auth-2.59.1 → google_auth-2.60.0}/tests/oauth2/test_webauthn_types.py +0 -0
  160. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test__cache.py +0 -0
  161. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test__cloud_sdk.py +0 -0
  162. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test__default.py +0 -0
  163. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test__exponential_backoff.py +0 -0
  164. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test__helpers.py +0 -0
  165. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test__oauth2client.py +0 -0
  166. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test__refresh_worker.py +0 -0
  167. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test__regional_access_boundary_utils.py +0 -0
  168. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test__service_account_info.py +0 -0
  169. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_agent_identity_utils.py +0 -0
  170. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_api_key.py +0 -0
  171. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_app_engine.py +0 -0
  172. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_aws.py +0 -0
  173. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_credentials.py +0 -0
  174. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_credentials_async.py +0 -0
  175. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_downscoped.py +0 -0
  176. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_exceptions.py +0 -0
  177. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_external_account.py +0 -0
  178. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_external_account_authorized_user.py +0 -0
  179. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_iam.py +0 -0
  180. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_identity_pool.py +0 -0
  181. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_impersonated_credentials.py +0 -0
  182. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_jwt.py +0 -0
  183. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_metrics.py +0 -0
  184. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_packaging.py +0 -0
  185. {google_auth-2.59.1 → google_auth-2.60.0}/tests/test_pluggable.py +0 -0
  186. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/__init__.py +0 -0
  187. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/aio/conftest.py +0 -0
  188. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/aio/test_aiohttp.py +0 -0
  189. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/aio/test_mtls.py +0 -0
  190. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/aio/test_sessions_mtls.py +0 -0
  191. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/aioresponses_compat.py +0 -0
  192. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/compliance.py +0 -0
  193. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/test__custom_tls_signer.py +0 -0
  194. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/test__http_client.py +0 -0
  195. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/test__mtls_helper.py +0 -0
  196. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/test_aio_mtls_helper.py +0 -0
  197. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/test_grpc.py +0 -0
  198. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/test_mtls.py +0 -0
  199. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/test_requests.py +0 -0
  200. {google_auth-2.59.1 → google_auth-2.60.0}/tests/transport/test_urllib3.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-auth
3
- Version: 2.59.1
3
+ Version: 2.60.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
@@ -24,8 +24,9 @@ import warnings
24
24
  from contextlib import asynccontextmanager
25
25
  from typing import TYPE_CHECKING, Mapping, Optional, Union
26
26
 
27
+ import google.auth.credentials
27
28
  import google.auth.transport._mtls_helper
28
- from google.auth import _exponential_backoff, exceptions
29
+ from google.auth import _exponential_backoff, _helpers, exceptions
29
30
  from google.auth.aio import transport
30
31
  from google.auth.aio.credentials import Credentials
31
32
  from google.auth.aio.transport import mtls
@@ -104,6 +105,106 @@ async def timeout_guard(timeout):
104
105
  _remaining_time()
105
106
 
106
107
 
108
+ class _SyncCredentialsAdapter(Credentials):
109
+ """Adapts synchronous credentials to the asynchronous credentials interface.
110
+
111
+ :class:`AsyncAuthorizedSession` wraps :class:`google.auth.credentials.Credentials`
112
+ (e.g. application default credentials) with this adapter so that they can be
113
+ used with an asynchronous transport. Calls are delegated to the wrapped
114
+ credentials using a synchronous transport, and blocking calls such as
115
+ refreshing the access token run in a worker thread so that the event loop
116
+ is not blocked.
117
+
118
+ Args:
119
+ credentials (google.auth.credentials.Credentials): The synchronous
120
+ credentials to adapt.
121
+ """
122
+
123
+ def __init__(self, credentials: google.auth.credentials.Credentials):
124
+ self._credentials = credentials
125
+ # Synchronous credentials cannot use the asynchronous transport of the
126
+ # session, so they are called with a synchronous transport instead.
127
+ self._sync_request_instance = None
128
+ # Synchronous credentials are not safe to refresh concurrently, which
129
+ # concurrent requests would otherwise do from multiple worker threads.
130
+ # Instead, at most one refresh is in flight and concurrent callers share it.
131
+ self._pending_refresh: Optional["asyncio.Task[None]"] = None
132
+
133
+ @property
134
+ def _sync_request(self):
135
+ if self._sync_request_instance is None:
136
+ # Imported here because `requests` is an optional dependency of
137
+ # google-auth. It is installed alongside `aiohttp` by the `aiohttp` extra.
138
+ from google.auth.transport import requests as sync_requests
139
+
140
+ self._sync_request_instance = sync_requests.Request()
141
+ return self._sync_request_instance
142
+
143
+ def close(self):
144
+ if (
145
+ self._sync_request_instance is not None
146
+ and hasattr(self._sync_request_instance, "session")
147
+ and self._sync_request_instance.session is not None
148
+ ):
149
+ self._sync_request_instance.session.close()
150
+
151
+ @property
152
+ def token(self):
153
+ """Optional[str]: The bearer token that can be used in HTTP headers to make
154
+ authenticated requests."""
155
+ return self._credentials.token
156
+
157
+ @property
158
+ def expiry(self):
159
+ """Optional[datetime]: When the token expires and is no longer valid.
160
+ If this is None, the token is assumed to never expire."""
161
+ return self._credentials.expiry
162
+
163
+ @property
164
+ @_helpers.copy_docstring(google.auth.credentials.Credentials)
165
+ def valid(self):
166
+ return self._credentials.valid
167
+
168
+ @property
169
+ @_helpers.copy_docstring(google.auth.credentials.Credentials)
170
+ def expired(self):
171
+ return self._credentials.expired
172
+
173
+ async def _refresh_shared(self):
174
+ """Refreshes the wrapped credentials, joining a refresh already in flight.
175
+
176
+ The refresh is shielded from cancellation: a caller that is cancelled
177
+ while waiting (e.g. because of a timeout) stops waiting, but the refresh
178
+ completes so that the next caller joins it rather than starting a
179
+ second, concurrent refresh.
180
+ """
181
+ if self._pending_refresh is None or self._pending_refresh.done():
182
+ self._pending_refresh = asyncio.create_task(
183
+ asyncio.to_thread(self._credentials.refresh, self._sync_request)
184
+ )
185
+ await asyncio.shield(self._pending_refresh)
186
+
187
+ @_helpers.copy_docstring(Credentials)
188
+ async def apply(self, headers, token=None):
189
+ self._credentials.apply(headers, token=token)
190
+
191
+ @_helpers.copy_docstring(Credentials)
192
+ async def refresh(self, request):
193
+ await self._refresh_shared()
194
+
195
+ @_helpers.copy_docstring(Credentials)
196
+ async def before_request(self, request, method, url, headers):
197
+ if not self._credentials.valid:
198
+ await self._refresh_shared()
199
+ await asyncio.to_thread(
200
+ self._credentials.before_request,
201
+ self._sync_request,
202
+ method,
203
+ url,
204
+ headers,
205
+ )
206
+
207
+
107
208
  class AsyncAuthorizedSession:
108
209
  """This is an asynchronous implementation of :class:`google.auth.requests.AuthorizedSession` class.
109
210
  We utilize an instance of a class that implements :class:`google.auth.aio.transport.Request` configured
@@ -126,8 +227,9 @@ class AsyncAuthorizedSession:
126
227
  credentials' headers to the request and refreshing credentials as needed.
127
228
 
128
229
  Args:
129
- credentials (google.auth.aio.credentials.Credentials):
130
- The credentials to add to the request.
230
+ credentials (Union[google.auth.aio.credentials.Credentials, google.auth.credentials.Credentials]):
231
+ The credentials to add to the request. Synchronous credentials
232
+ (e.g. application default credentials) are also supported.
131
233
  auth_request (Optional[google.auth.aio.transport.Request]):
132
234
  An instance of a class that implements
133
235
  :class:`~google.auth.aio.transport.Request` used to make requests
@@ -139,17 +241,22 @@ class AsyncAuthorizedSession:
139
241
  - google.auth.exceptions.TransportError: If `auth_request` is `None`
140
242
  and the external package `aiohttp` is not installed.
141
243
  - google.auth.exceptions.InvalidType: If the provided credentials are
142
- not of type `google.auth.aio.credentials.Credentials`.
244
+ not of type `google.auth.aio.credentials.Credentials` or
245
+ `google.auth.credentials.Credentials`.
143
246
  """
144
247
 
145
248
  def __init__(
146
- self, credentials: Credentials, auth_request: Optional[transport.Request] = None
249
+ self,
250
+ credentials: Union[Credentials, google.auth.credentials.Credentials],
251
+ auth_request: Optional[transport.Request] = None,
147
252
  ):
148
- if not isinstance(credentials, Credentials):
253
+ if isinstance(credentials, google.auth.credentials.Credentials):
254
+ credentials = _SyncCredentialsAdapter(credentials)
255
+ elif not isinstance(credentials, Credentials):
149
256
  raise exceptions.InvalidType(
150
- f"The configured credentials of type {type(credentials)} are invalid and must be of type `google.auth.aio.credentials.Credentials`"
257
+ f"The configured credentials of type {type(credentials)} are invalid and must be of type `google.auth.aio.credentials.Credentials` or `google.auth.credentials.Credentials`"
151
258
  )
152
- self._credentials = credentials
259
+ self._credentials: Credentials = credentials
153
260
  _auth_request = auth_request
154
261
  if not _auth_request and AIOHTTP_INSTALLED:
155
262
  _auth_request = AiohttpRequest()
@@ -846,6 +953,8 @@ class AsyncAuthorizedSession:
846
953
  if inspect.isawaitable(res):
847
954
  await res
848
955
  finally:
956
+ if hasattr(self._credentials, "close"):
957
+ self._credentials.close()
849
958
  for old_request in self._old_auth_requests:
850
959
  try:
851
960
  if hasattr(old_request, "close"):
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = "2.59.1"
15
+ __version__ = "2.60.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-auth
3
- Version: 2.59.1
3
+ Version: 2.60.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
@@ -13,13 +13,17 @@
13
13
  # limitations under the License.
14
14
 
15
15
  import asyncio
16
+ import http.client as http_client
17
+ import threading
16
18
  from typing import AsyncGenerator
17
- from unittest.mock import Mock, patch
19
+ from unittest.mock import AsyncMock, Mock, patch
18
20
 
19
21
  import pytest # type: ignore
20
22
  from aioresponses import aioresponses # type: ignore
21
23
 
22
- from google.auth.aio.credentials import AnonymousCredentials
24
+ import google.auth.credentials
25
+ import google.auth.transport.requests
26
+ from google.auth.aio.credentials import AnonymousCredentials, Credentials
23
27
  from google.auth.aio.transport import (
24
28
  _DEFAULT_TIMEOUT_SECONDS,
25
29
  DEFAULT_MAX_RETRY_ATTEMPTS,
@@ -28,7 +32,12 @@ from google.auth.aio.transport import (
28
32
  Response,
29
33
  sessions,
30
34
  )
31
- from google.auth.exceptions import InvalidType, TimeoutError, TransportError
35
+ from google.auth.exceptions import (
36
+ InvalidType,
37
+ RefreshError,
38
+ TimeoutError,
39
+ TransportError,
40
+ )
32
41
 
33
42
 
34
43
  @pytest.fixture
@@ -203,9 +212,77 @@ class TestAsyncAuthorizedSession(object):
203
212
  sessions.AsyncAuthorizedSession(credentials)
204
213
 
205
214
  exc.match(
206
- f"The configured credentials of type {type(credentials)} are invalid and must be of type `google.auth.aio.credentials.Credentials`"
215
+ f"The configured credentials of type {type(credentials)} are invalid and must be of type `google.auth.aio.credentials.Credentials` or `google.auth.credentials.Credentials`"
207
216
  )
208
217
 
218
+ @pytest.mark.asyncio
219
+ async def test_constructor_with_sync_credentials(self):
220
+ sync_credentials = google.auth.credentials.AnonymousCredentials()
221
+ authed_session = sessions.AsyncAuthorizedSession(
222
+ sync_credentials, auth_request=MockRequest()
223
+ )
224
+
225
+ # Synchronous credentials are adapted to the asynchronous credentials interface.
226
+ assert isinstance(authed_session._credentials, Credentials)
227
+ assert isinstance(authed_session._credentials, sessions._SyncCredentialsAdapter)
228
+ assert authed_session._credentials._credentials is sync_credentials
229
+ with patch.object(
230
+ authed_session._credentials,
231
+ "close",
232
+ wraps=authed_session._credentials.close,
233
+ ) as mock_close:
234
+ await authed_session.close()
235
+ mock_close.assert_called_once()
236
+
237
+ @pytest.mark.asyncio
238
+ async def test_request_with_sync_credentials_success(self, mocked_content):
239
+ sync_credentials = Mock(spec=google.auth.credentials.Credentials)
240
+ mocked_response = MockResponse(
241
+ status_code=http_client.OK,
242
+ headers={"Content-Type": "application/json"},
243
+ content=mocked_content,
244
+ )
245
+ auth_request = MockRequest(mocked_response)
246
+ authed_session = sessions.AsyncAuthorizedSession(sync_credentials, auth_request)
247
+
248
+ response = await authed_session.request(
249
+ "GET", self.TEST_URL, headers={"x-test": "value"}
250
+ )
251
+
252
+ assert response.status_code == http_client.OK
253
+ assert await response.read() == b"Cavefish have no sight."
254
+ # The synchronous credentials are invoked with a synchronous transport rather
255
+ # than the asynchronous transport of the session.
256
+ sync_credentials.before_request.assert_called_once()
257
+ request, method, url, headers = sync_credentials.before_request.call_args.args
258
+ assert isinstance(request, google.auth.transport.requests.Request)
259
+ assert method == "GET"
260
+ assert url == self.TEST_URL
261
+ assert headers == {"x-test": "value"}
262
+ await authed_session.close()
263
+
264
+ @pytest.mark.asyncio
265
+ async def test_request_with_sync_credentials_refreshes_on_unauthorized(self):
266
+ sync_credentials = Mock(spec=google.auth.credentials.Credentials)
267
+ unauthorized_response = MockResponse(status_code=http_client.UNAUTHORIZED)
268
+ ok_response = MockResponse(status_code=http_client.OK)
269
+ auth_request = AsyncMock(side_effect=[unauthorized_response, ok_response])
270
+ authed_session = sessions.AsyncAuthorizedSession(
271
+ sync_credentials, auth_request=auth_request
272
+ )
273
+
274
+ response = await authed_session.request("GET", self.TEST_URL)
275
+
276
+ assert response is ok_response
277
+ assert auth_request.call_count == 2
278
+ assert unauthorized_response._close
279
+ sync_credentials.refresh.assert_called_once()
280
+ (refresh_request,) = sync_credentials.refresh.call_args.args
281
+ assert isinstance(refresh_request, google.auth.transport.requests.Request)
282
+ # The same synchronous transport is reused for every call to the credentials.
283
+ assert refresh_request is sync_credentials.before_request.call_args.args[0]
284
+ await authed_session.close()
285
+
209
286
  @pytest.mark.asyncio
210
287
  async def test_request_default_auth_request_success(self):
211
288
  with aioresponses() as m:
@@ -368,3 +445,179 @@ def test_mock_request_clone():
368
445
  request = MockRequest()
369
446
  cloned = request._clone()
370
447
  assert cloned is request
448
+
449
+
450
+ class BlockingRefreshCredentials(google.auth.credentials.Credentials):
451
+ """Synchronous credentials whose refresh blocks until released by the test."""
452
+
453
+ def __init__(self):
454
+ super().__init__()
455
+ self.refresh_calls = 0
456
+ self.in_flight_refreshes = 0
457
+ self.max_in_flight_refreshes = 0
458
+ self.refresh_started = threading.Event()
459
+ self.release_refresh = threading.Event()
460
+
461
+ def refresh(self, request):
462
+ self.refresh_calls += 1
463
+ self.in_flight_refreshes += 1
464
+ self.max_in_flight_refreshes = max(
465
+ self.max_in_flight_refreshes, self.in_flight_refreshes
466
+ )
467
+ self.refresh_started.set()
468
+ self.release_refresh.wait(timeout=5)
469
+ self.in_flight_refreshes -= 1
470
+ self.token = "token"
471
+
472
+
473
+ class TestSyncCredentialsAdapter(object):
474
+ TEST_URL = "http://example.com/"
475
+
476
+ @pytest.mark.asyncio
477
+ async def test_delegates_to_sync_credentials(self):
478
+ sync_credentials = Mock(spec=google.auth.credentials.Credentials)
479
+ sync_credentials.token = "sync-token"
480
+ sync_credentials.expiry = Mock()
481
+ sync_credentials.valid = True
482
+ sync_credentials.expired = False
483
+ adapter = sessions._SyncCredentialsAdapter(sync_credentials)
484
+ headers = {}
485
+
486
+ await adapter.before_request(Mock(), "GET", self.TEST_URL, headers)
487
+ await adapter.refresh(Mock())
488
+ await adapter.apply(headers, token="token")
489
+
490
+ assert adapter.token == "sync-token"
491
+ assert adapter.expiry is sync_credentials.expiry
492
+ assert adapter.valid is True
493
+ assert adapter.expired is False
494
+
495
+ # The same synchronous transport is used for every call.
496
+ sync_request = sync_credentials.before_request.call_args.args[0]
497
+ assert isinstance(sync_request, google.auth.transport.requests.Request)
498
+ sync_credentials.before_request.assert_called_once_with(
499
+ sync_request, "GET", self.TEST_URL, headers
500
+ )
501
+ sync_credentials.refresh.assert_called_once_with(sync_request)
502
+ sync_credentials.apply.assert_called_once_with(headers, token="token")
503
+ with patch.object(sync_request.session, "close") as mock_close:
504
+ adapter.close()
505
+ mock_close.assert_called_once()
506
+
507
+ @pytest.mark.asyncio
508
+ async def test_blocking_calls_run_off_the_event_loop_thread(self):
509
+ sync_credentials = Mock(spec=google.auth.credentials.Credentials)
510
+ thread_ids = []
511
+ sync_credentials.before_request.side_effect = lambda *args: thread_ids.append(
512
+ threading.get_ident()
513
+ )
514
+ sync_credentials.refresh.side_effect = lambda *args: thread_ids.append(
515
+ threading.get_ident()
516
+ )
517
+ adapter = sessions._SyncCredentialsAdapter(sync_credentials)
518
+
519
+ await adapter.before_request(Mock(), "GET", self.TEST_URL, {})
520
+ await adapter.refresh(Mock())
521
+
522
+ assert len(thread_ids) == 2
523
+ assert threading.get_ident() not in thread_ids
524
+
525
+ @pytest.mark.asyncio
526
+ async def test_concurrent_before_request_refreshes_once(self):
527
+ sync_credentials = BlockingRefreshCredentials()
528
+ adapter = sessions._SyncCredentialsAdapter(sync_credentials)
529
+ headers = [{} for _ in range(5)]
530
+
531
+ tasks = [
532
+ asyncio.create_task(adapter.before_request(Mock(), "GET", self.TEST_URL, h))
533
+ for h in headers
534
+ ]
535
+ await asyncio.to_thread(sync_credentials.refresh_started.wait, 5)
536
+ # Yield to the event loop so all tasks run until they await the refresh.
537
+ await asyncio.sleep(0)
538
+ sync_credentials.release_refresh.set()
539
+ await asyncio.gather(*tasks)
540
+
541
+ assert sync_credentials.refresh_calls == 1
542
+ assert all(h["authorization"] == "Bearer token" for h in headers)
543
+
544
+ @pytest.mark.asyncio
545
+ async def test_refresh_and_before_request_share_one_refresh(self):
546
+ sync_credentials = BlockingRefreshCredentials()
547
+ adapter = sessions._SyncCredentialsAdapter(sync_credentials)
548
+ headers = {}
549
+
550
+ refresh_task = asyncio.create_task(adapter.refresh(Mock()))
551
+ await asyncio.to_thread(sync_credentials.refresh_started.wait, 5)
552
+ before_request_task = asyncio.create_task(
553
+ adapter.before_request(Mock(), "GET", self.TEST_URL, headers)
554
+ )
555
+ # Yield to the event loop so before_request_task reaches the refresh.
556
+ await asyncio.sleep(0)
557
+ sync_credentials.release_refresh.set()
558
+ await asyncio.gather(refresh_task, before_request_task)
559
+
560
+ assert sync_credentials.max_in_flight_refreshes == 1
561
+ assert sync_credentials.refresh_calls == 1
562
+ assert headers["authorization"] == "Bearer token"
563
+
564
+ @pytest.mark.asyncio
565
+ async def test_cancelled_caller_does_not_abandon_refresh(self):
566
+ sync_credentials = BlockingRefreshCredentials()
567
+ adapter = sessions._SyncCredentialsAdapter(sync_credentials)
568
+
569
+ cancelled_task = asyncio.create_task(
570
+ adapter.before_request(Mock(), "GET", self.TEST_URL, {})
571
+ )
572
+ await asyncio.to_thread(sync_credentials.refresh_started.wait, 5)
573
+ cancelled_task.cancel()
574
+ with pytest.raises(asyncio.CancelledError):
575
+ await cancelled_task
576
+
577
+ # The refresh started on behalf of the cancelled request is still running:
578
+ # a new request must wait for it rather than start a second refresh.
579
+ headers = {}
580
+ waiting_task = asyncio.create_task(
581
+ adapter.before_request(Mock(), "GET", self.TEST_URL, headers)
582
+ )
583
+ await asyncio.sleep(0)
584
+ assert not waiting_task.done()
585
+ sync_credentials.release_refresh.set()
586
+ await waiting_task
587
+
588
+ assert sync_credentials.refresh_calls == 1
589
+ assert sync_credentials.max_in_flight_refreshes == 1
590
+ assert headers["authorization"] == "Bearer token"
591
+
592
+ @pytest.mark.asyncio
593
+ async def test_failed_refresh_is_not_reused(self):
594
+ sync_credentials = Mock(spec=google.auth.credentials.Credentials)
595
+ sync_credentials.refresh.side_effect = [RefreshError("refresh failed"), None]
596
+ adapter = sessions._SyncCredentialsAdapter(sync_credentials)
597
+
598
+ with pytest.raises(RefreshError):
599
+ await adapter.refresh(Mock())
600
+ await adapter.refresh(Mock())
601
+
602
+ assert sync_credentials.refresh.call_count == 2
603
+
604
+ @pytest.mark.asyncio
605
+ async def test_before_request_with_valid_credentials_does_not_wait_for_refresh(
606
+ self,
607
+ ):
608
+ sync_credentials = BlockingRefreshCredentials()
609
+ sync_credentials.token = "token"
610
+ adapter = sessions._SyncCredentialsAdapter(sync_credentials)
611
+ headers = {}
612
+
613
+ refresh_task = asyncio.create_task(adapter.refresh(Mock()))
614
+ await asyncio.to_thread(sync_credentials.refresh_started.wait, 5)
615
+ # Requests that already have a valid token must not wait for the refresh.
616
+ await asyncio.wait_for(
617
+ adapter.before_request(Mock(), "GET", self.TEST_URL, headers), timeout=5
618
+ )
619
+ assert headers["authorization"] == "Bearer token"
620
+
621
+ sync_credentials.release_refresh.set()
622
+ await refresh_task
623
+ assert sync_credentials.refresh_calls == 1
File without changes
File without changes
File without changes