Pyjo.GCP.Credentials.AuthorizedUser - Credentials of a user of gcloud

from Pyjo.GCP.Credentials.AuthorizedUser import AuthorizedUser

provider = AuthorizedUser(client_id='764086051850-...', client_secret='...',
                          refresh_token='1//0g...')
print(provider.credentials().token)

# Or import the module, as in Google Python Style Guide

import Pyjo.GCP.Config
import Pyjo.GCP.Credentials.AuthorizedUser

config = Pyjo.GCP.Config.new()
info = config.credentials_info(config.adc_file())
provider = Pyjo.GCP.Credentials.AuthorizedUser.AuthorizedUser.from_info(info)
provider.credentials_p().then(lambda credentials: print(credentials.expiration)).wait()

Pyjo.GCP.Credentials.AuthorizedUser is the provider of the credentials of a user, of a file of the type authorized_user, as gcloud auth application-default login writes it: the refresh token of the user, which the token endpoint of OAuth 2.0 of Google exchanges for an access token, with the client of gcloud.

{
  "type": "authorized_user",
  "client_id": "764086051850-....apps.googleusercontent.com",
  "client_secret": "...",
  "refresh_token": "1//0g...",
  "quota_project_id": "myproject",
  "account": "me@example.com",
  "universe_domain": "googleapis.com"
}

The token has the scopes of the login, as the request of the refresh token has none, as google-auth does for the Application Default Credentials. 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/4113.

Classes

class Pyjo.GCP.Credentials.AuthorizedUser.Pyjo_GCP_Credentials_AuthorizedUser(*, client_id: str, client_secret: str, refresh_token: str, token_uri: str | None = None, quota_project: str | None = None, universe_domain: str | None = None, account: str | None = None, **kwargs: Any)[source]

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

__init__(*, client_id: str, client_secret: str, refresh_token: str, token_uri: str | None = None, quota_project: str | None = None, universe_domain: str | None = None, account: str | None = None, **kwargs: Any) → None[source]
provider = Pyjo.GCP.Credentials.AuthorizedUser.new(client_id=client_id, client_secret=client_secret,
                                                   refresh_token=refresh_token)

Construct a new Pyjo.GCP.Credentials.AuthorizedUser object, with the options of Pyjo.GCP.Credentials.Provider.

account
account = provider.account

The email of the user, or None.

client_id
client_id = provider.client_id

The ID of the client of OAuth 2.0, as the one of gcloud.

client_secret
client_secret = provider.client_secret

The secret of the client of OAuth 2.0.

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

The access token of the refresh token.

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

A new provider of the JSON object of a file of the type authorized_user, with quota_project_id, universe_domain, account and token_uri of the file, and the arguments over them, or a Pyjo.Exception of a file without client_id, client_secret or refresh_token.

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.

token_uri
url = provider.token_uri

The token endpoint of OAuth 2.0, https://oauth2.googleapis.com/token by default.

universe_domain
domain = provider.universe_domain

The universe domain of the credentials, or None.

Pyjo.GCP.Credentials.AuthorizedUser.TOKEN_URI = 'https://oauth2.googleapis.com/token'

The token endpoint of OAuth 2.0 of Google.