Skip to main content

Python Client for Google Cloud Auth

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcloud-aio-auth-3.4.5.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcloud_aio_auth-3.4.5-py2.py3-none-any.whl (16.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file gcloud-aio-auth-3.4.5.tar.gz.

File metadata

  • Download URL: gcloud-aio-auth-3.4.5.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.0

File hashes

Hashes for gcloud-aio-auth-3.4.5.tar.gz
Algorithm Hash digest
SHA256 bae251858423e3d2e85d4e1a4c359e45239c9f6c90826466054a069431e8ec4a
MD5 2f2fe90a6ea8ad5780fd985c20a19823
BLAKE2b-256 9c90d198d2c004168696c6240a6a542653bef811bac8c1ced6dd20dd9f03feb4

See more details on using hashes here.

File details

Details for the file gcloud_aio_auth-3.4.5-py2.py3-none-any.whl.

File metadata

  • Download URL: gcloud_aio_auth-3.4.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.0

File hashes

Hashes for gcloud_aio_auth-3.4.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ecbe456cf4763df3c4d3323c899700c8cad67b4e4e0013de23473c7d926b95c9
MD5 e5a30ce5eb543c8742c07f9ba395307c
BLAKE2b-256 f720bf87610257466e729ec866ea2a9cd7fb40add48e98bc23287150f4da9cf4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page