Skip to main content

(Asyncio OR Threadsafe) Python Client for Google Cloud Auth

This is a shared codebase for gcloud-aio-auth and gcloud-rest-auth

This library implements an IamClient class, which can be used to interact with GCP public keys and URL sign blobs.

It additionally implements a Token class, which is used for authorizing against Google Cloud. The other gcloud-aio-* package components accept a Token instance as an argument; you can define a single token for all of these components or define one for each. Each component corresponds to a given Google Cloud service and each service requires “scopes”.

Latest PyPI Version (gcloud-aio-auth) Python Version Support (gcloud-aio-auth) Python Version Support (gcloud-rest-auth)

Installation

$ pip install --upgrade gcloud-{aio,rest}-auth

Usage

from gcloud.aio.auth import IamClient

client = IamClient()
pubkeys = await client.list_public_keys()


from gcloud.rest.auth import Token

token = Token()
print(token.get())

Additionally, the Token constructor accepts the following optional arguments:

  • service_file: path to a service account, authorized user file, or any other application credentials. Alternatively, you can pass a file-like object, like an io.StringIO instance, in case your credentials are not stored in a file but in memory. If omitted, will attempt to find one on your path or fallback to generating a token from GCE metadata.

  • session: an aiohttp.ClientSession instance to be used for all requests. If omitted, a default session will be created. If you use the default session, you may be interested in using Token() as a context manager (async with Token(..) as token:) or explicitly calling the Token.close() method to ensure the session is cleaned up appropriately.

  • scopes: an optional list of GCP scopes for which to generate our token. Only valid (and required!) for service account authentication.

CLI

This project can also be used to help you manually authenticate to test GCP routes, eg. we can list our project’s uptime checks with a tool such as curl:

# using default application credentials
curl \
  -H "Authorization: Bearer $(python3 -c 'from gcloud.rest.auth import Token; print(Token().get())')" \
  "https://monitoring.googleapis.com/v3/projects/PROJECT_ID/uptimeCheckConfigs"

# using a service account (make sure to provide a scope!)
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service.json
curl \
  -H "Authorization: Bearer $(python3 -c 'from gcloud.rest.auth import Token; print(Token(scopes=["'"https://www.googleapis.com/auth/cloud-platform"'"]).get())')" \
  "https://monitoring.googleapis.com/v3/projects/PROJECT_ID/uptimeCheckConfigs"

# using legacy account credentials
export GOOGLE_APPLICATION_CREDENTIALS=~/.config/gcloud/legacy_credentials/EMAIL@DOMAIN.TLD/adc.json
curl \
  -H "Authorization: Bearer $(python3 -c 'from gcloud.rest.auth import Token; print(Token().get())')" \
  "https://monitoring.googleapis.com/v3/projects/PROJECT_ID/uptimeCheckConfigs"

Contributing

Please see our contributing guide.

Metadata

Release files for gcloud-aio-auth 3.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gcloud-aio-auth 3.4.4
File Size Uploaded Provenance Actions
gcloud-aio-auth-3.4.4.tar.gz 14.6 kB Without provenance Details for gcloud-aio-auth-3.4.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gcloud-aio-auth 3.4.4
File Interpreter ABI Platform Actions
gcloud_aio_auth-3.4.4-py2.py3-none-any.whl Python 2, Python 3 none any Details for gcloud_aio_auth-3.4.4-py2.py3-none-any.whl

Total release size: 30.7 kB

Release files / gcloud-aio-auth-3.4.4.tar.gz

Download URL gcloud-aio-auth-3.4.4.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9310c36257b37eb1f1d29d7822aa457dbd613d4d4dc2e82dd8be1d99987c2ae7
BLAKE2b-256 checksum
How to use checksums
2af52aa6516f037c9bac60d4e980887d5f179ca7f0ab1907e57b987d2a7529de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.0

Release files / gcloud_aio_auth-3.4.4-py2.py3-none-any.whl

Download URL gcloud_aio_auth-3.4.4-py2.py3-none-any.whl
Size 16.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2af66439511504c5360d9430aadef4713277a558ec80076154551bb6860f4dc1
BLAKE2b-256 checksum
How to use checksums
3f4d330b14e504acc338b56b5783ec822d1a858a6694d7eb7ff447bb3b295fe0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.0

Security for gcloud-aio-auth 3.4.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.4.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page