gcloud-aio-auth is an asyncio-compatible Python client library for Google Cloud Authentication. It provides asynchronous primitives for managing access tokens, IAP tokens, and interacting with IAM. Part of the broader `gcloud-aio` monorepo, it offers async interfaces to various Google Cloud services. The current version is 5.4.4, with releases occurring as part of the actively developed monorepo, often tied to dependency updates or new feature rollouts across components.
pip install gcloud-aio-authVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `Token` class, which handles credential discovery (via `GOOGLE_APPLICATION_CREDENTIALS` or Application Default Credentials) and automatic token refreshing. It then shows how to use the obtained access token to make an authenticated request using `aiohttp.ClientSession` to a Google Cloud API. Remember to run `gcloud auth application-default login` for local development or set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.
Upgrade Python environment to version 3.10 or later.
Upgrade to gcloud-aio-auth>=5.4.4. If manually managing `aiohttp.ClientSession`, ensure `auto_decompress=None` is explicitly set on the `Token` (or other gcloud-aio client) constructor if you want to avoid overwriting your session's setting.
Always initialize `gcloud.aio.auth.Token` (or `IapToken`) as described in `gcloud-aio-auth` documentation, letting it handle credential discovery or providing a `service_file` directly. Do not attempt to pass `google.auth.default()` credential objects to `gcloud-aio` client constructors.
Ensure `Token` instances are closed. The recommended pattern is `async with Token(...) as token:` or, if not using a context manager, explicitly call `await token.close()` before your application exits.
Ensure you are using a JSON service account key downloaded from the Google Cloud Console (IAM & Admin -> Service Accounts -> Keys -> Add Key -> Create new key -> JSON), and that this file is correctly passed to `gcloud.aio.auth.Token(service_file=...)`.
Authenticate locally by running `gcloud auth application-default login` in your terminal, or set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the absolute path of your service account JSON key file (e.g., `export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"`).
Increase the `timeout` parameter when initializing `gcloud.aio.auth.Token` or when making requests, and consider implementing robust retry logic with exponential backoff for network operations.
Ensure that `google-api-core`, `grpcio`, and all `google-cloud-*` packages are updated to their latest compatible versions or pinned to known stable versions that work well together (e.g., `pip install --upgrade google-api-core grpcio` or, if necessary, pin `google-api-core==1.17.0` as was a past solution for similar issues).