Pyjo.GCP.Credentials.ExternalAccountAuthorizedUser - Credentials of a user of a workforce pool

import Pyjo.GCP.Config
import Pyjo.GCP.Credentials.ExternalAccountAuthorizedUser

config = Pyjo.GCP.Config.new()
info = config.credentials_info(config.adc_file())
provider = Pyjo.GCP.Credentials.ExternalAccountAuthorizedUser.ExternalAccountAuthorizedUser.from_info(info)
print(provider.credentials().token)

Pyjo.GCP.Credentials.ExternalAccountAuthorizedUser is the provider of the credentials of a user of Workforce Identity Federation, of a file of the type external_account_authorized_user, as gcloud auth application-default login --login-config writes it: the refresh token of the user, which the Security Token Service of Google exchanges for an access token, with the basic authentication of the OAuth client of the workforce pool.

{
  "type": "external_account_authorized_user",
  "audience": "//iam.googleapis.com/locations/global/workforcePools/pool/providers/oidc",
  "client_id": "...",
  "client_secret": "...",
  "refresh_token": "...",
  "token_url": "https://sts.googleapis.com/v1/oauthtoken",
  "token_info_url": "https://sts.googleapis.com/v1/introspect",
  "universe_domain": "googleapis.com"
}

An access token of the file, with token and expiry, is the first one, until it is about to expire, and a file without the refresh token has only that one. The token has the scopes of the login, as the request of the refresh token has none, as google-auth has it, and a new refresh token of the response replaces the one of the provider.

See also

Pyjo.GCP.Credentials.Provider, Pyjo.GCP.Credentials.File, https://google.aip.dev/auth/4117, https://cloud.google.com/iam/docs/workforce-obtaining-short-lived-credentials.

Classes

class Pyjo.GCP.Credentials.ExternalAccountAuthorizedUser.Pyjo_GCP_Credentials_ExternalAccountAuthorizedUser(*, refresh_token: str | None = None, token_url: str | None = None, client_id: str | None = None, client_secret: str | None = None, audience: str | None = None, token: str | None = None, expiration: datetime | None = None, quota_project: str | None = None, universe_domain: str | None = None, **kwargs: Any)[source]

Pyjo.GCP.Credentials.ExternalAccountAuthorizedUser inherits all attributes and methods from Pyjo.GCP.Credentials.Provider and implements the following new ones.

__init__(*, refresh_token: str | None = None, token_url: str | None = None, client_id: str | None = None, client_secret: str | None = None, audience: str | None = None, token: str | None = None, expiration: datetime | None = None, quota_project: str | None = None, universe_domain: str | None = None, **kwargs: Any) → None[source]
provider = Pyjo.GCP.Credentials.ExternalAccountAuthorizedUser.new(
    refresh_token=refresh_token, token_url='https://sts.googleapis.com/v1/oauthtoken',
    client_id=client_id, client_secret=client_secret)

Construct a new Pyjo.GCP.Credentials.ExternalAccountAuthorizedUser object, with the options of Pyjo.GCP.Credentials.Provider, or a Pyjo.Exception without the fields of a refresh or a token.

audience
audience = provider.audience

The resource name of the provider of the workforce pool, or None.

client_id
client_id = provider.client_id

The ID of the OAuth client of the workforce pool, or None.

client_secret
secret = provider.client_secret

The secret of the OAuth client, or None.

async fetch() → Pyjo_GCP_Credentials[source]
credentials = await provider.fetch()

The access token of the refresh token, or a Pyjo.Exception without one.

classmethod from_info(info: Mapping[str, Any], **kwargs: Any) → Self[source]
provider = ExternalAccountAuthorizedUser.from_info(info)
provider = ExternalAccountAuthorizedUser.from_info(info, ua=ua)

A new provider of the JSON object of a file of the type external_account_authorized_user, with the fields of the file and the arguments over them.

quota_project
project = provider.quota_project

The quota project of the credentials, or None.

refresh_token
refresh_token = provider.refresh_token

The refresh token of the user, or None.

token_url
url = provider.token_url

The token endpoint of the refresh, as https://sts.googleapis.com/v1/oauthtoken, or None.

universe_domain
domain = provider.universe_domain

The universe domain, googleapis.com by default.