Skip to main content

gcp-oidc

Generate OpenID Connect tokens for GCP service accounts

About

This library is a wrapper around the google-cloud-iam client library. It's primary function is to support automatically refreshing an expired id token.

How it Works

Two identities are involved in generating an id token: the caller, and the client service account for whom the credential is created. The caller is responsible for requesting a token from Google for the client service account.

The caller is a Google service account that's derived from the GOOGLE_APPLICATION_CREDENTIALS environment variable. Alternatively, the caller can be explicitly set through the client constructor by specifying a path to a service account file.

The client service account (for whom the credential is created) is automatically set to the caller service account if not explicitly provided.

The caller must have the serviceAccountTokenCreator role on the client service account in order to generate an id token for that account.

Examples

Install the package

pip install gcp-oidc

Generate an id token for the default service account.

from oidcutils import GCPOIDCClient

# Instantiate a OIDC client object and generate a token.
# Hang on to the client instance for future invocations.
# Any subsequent calls to get_id_token() will automatically 
# refresh the token if the token has expired.
client = GCPOIDCClient()
token = client.get_id_token()

Generate an id token for a specific client service account when you know the client service account email address.

from oidcutils import GCPOIDCClient

options = {
    'debug': True,
    'client_service_account_email': 'my-service-123@mygcproject.iam.gserviceaccount.com'
}
client = GCPOIDCClient(options)
token = client.get_id_token()

Generate an id token for a specific client service account when you have a client service account JSON key file.

from oidcutils import GCPOIDCClient

options = {
    'debug': True,
    'client_service_account_file': '/path_to_service_account_file.json'
}
client = GCPOIDCClient(options)
token = client.get_id_token()

Generate an id token for a specific client service account using a specific caller.

from oidcutils import GCPOIDCClient

options = {
    'debug': True,
    'caller_service_account_file': '/path_to_caller_service_account_file.json'
    'client_service_account_email': 'my-service-123@mygcproject.iam.gserviceaccount.com'
}
client = GCPOIDCClient(options)
token = client.get_id_token()

Client Methods and Properties

Property Description
expiry Date time when the token expires
audience The configured JWT audience claim
client_email The client email address

--

Method Description
refresh_id_token(options) Forces a token refresh. Takes an optional dict positional parameter. 'service_account_id' and 'audience' keys can be provided values. Return nothing.
get_id_token() Returns a valid id token

Metadata

Release files for gcp-oidc 0.0.12

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

Source distribution (sdist)

Source distribution for gcp-oidc 0.0.12
File Size Uploaded Provenance Actions
gcp-oidc-0.0.12.tar.gz 3.2 kB Without provenance Details for gcp-oidc-0.0.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gcp-oidc 0.0.12
File Interpreter ABI Platform Actions
gcp_oidc-0.0.12-py3-none-any.whl Python 3 none any Details for gcp_oidc-0.0.12-py3-none-any.whl

Total release size: 7.5 kB

Release files / gcp-oidc-0.0.12.tar.gz

Download URL gcp-oidc-0.0.12.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4e95faf9d60c90cc3dd58b8d308be5f19e69602f99393143bb7f0c6b8a2709aa
BLAKE2b-256 checksum
How to use checksums
fc9a95a693bb051dadb91c27f5d9b46dcfe72cefc6d54f6d2b6deb5a25d1e09d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.7

Release files / gcp_oidc-0.0.12-py3-none-any.whl

Download URL gcp_oidc-0.0.12-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ad5c7c0c58707445be271bf19c11c5709486590bf781feaea664928d90141f8
BLAKE2b-256 checksum
How to use checksums
7ac2c1662d263fe8a28655e403152fb9e90fe3f2f4c7c35b1260961385e730bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.7

Security for gcp-oidc 0.0.12

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.

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