Pyjo.GCP.Credentials.ServiceAccount - Credentials of the key of a service account¶
from Pyjo.GCP.Credentials.ServiceAccount import ServiceAccount
provider = ServiceAccount.from_info(info, scopes=['https://www.googleapis.com/auth/devstorage.read_only'])
print(provider.credentials().token)
# Or import the module, as in Google Python Style Guide
import Pyjo.GCP.Config
import Pyjo.GCP.Credentials.ServiceAccount
info = Pyjo.GCP.Config.new().credentials_info('/etc/gcloud/key.json')
# A self-signed JWT of AIP-4111, without a request
provider = Pyjo.GCP.Credentials.ServiceAccount.ServiceAccount.from_info(info, self_signed=True)
provider.credentials_p().then(lambda credentials: print(credentials.expiration)).wait()
Pyjo.GCP.Credentials.ServiceAccount is the provider of the
credentials of the key of a service account, of a file of the type
service_account, as the console of Google Cloud and
gcloud iam service-accounts keys create make it, of AIP-4112:
{
"type": "service_account",
"project_id": "myproject",
"private_key_id": "3c5a...",
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"client_email": "reader@myproject.iam.gserviceaccount.com",
"token_uri": "https://oauth2.googleapis.com/token",
"universe_domain": "googleapis.com"
}
The token is the access token of the JSON Web Token bearer grant of RFC 7523,
a JWT of RS256 of Pyjo.GCP.RSA with the scopes, which the token
endpoint exchanges, or, with self_signed, the JWT itself, of AIP-4111,
which the APIs of Google take as a token, without a request. A key of another
universe domain than googleapis.com has a self-signed JWT always, as
google-auth has it.
See also¶
Pyjo.GCP.Credentials.Provider, Pyjo.GCP.Credentials.File,
Pyjo.GCP.RSA, https://google.aip.dev/auth/4111,
https://google.aip.dev/auth/4112, RFC 7523.
Classes¶
- Pyjo.GCP.Credentials.ServiceAccount.GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:jwt-bearer'¶
The grant type of RFC 7523.
- Pyjo.GCP.Credentials.ServiceAccount.LIFETIME = 3600¶
The number of seconds that a JWT of the key is valid, an hour, as google-auth has it.
- class Pyjo.GCP.Credentials.ServiceAccount.Pyjo_GCP_Credentials_ServiceAccount(*, client_email: str, private_key: str, private_key_id: str | None = None, token_uri: str | None = None, scopes: Sequence[str] | None = None, subject: str | None = None, self_signed: bool = False, project: str | None = None, quota_project: str | None = None, universe_domain: str | None = None, **kwargs: Any)[source]¶
Pyjo.GCP.Credentials.ServiceAccountinherits all attributes and methods fromPyjo.GCP.Credentials.Providerand implements the following new ones.- __init__(*, client_email: str, private_key: str, private_key_id: str | None = None, token_uri: str | None = None, scopes: Sequence[str] | None = None, subject: str | None = None, self_signed: bool = False, project: str | None = None, quota_project: str | None = None, universe_domain: str | None = None, **kwargs: Any) None[source]¶
provider = Pyjo.GCP.Credentials.ServiceAccount.new(client_email=email, private_key=pem) provider = Pyjo.GCP.Credentials.ServiceAccount.new(client_email=email, private_key=pem, subject='admin@example.com')
Construct a new
Pyjo.GCP.Credentials.ServiceAccountobject, with the options ofPyjo.GCP.Credentials.Provider, or aPyjo.Exceptionof an invalid key.
- assertion(now: int | None = None) str[source]¶
jwt = provider.assertion()
The JWT of the grant of RFC 7523, with the email of the service account, the scopes, the
subject, and the audience ofhttps://oauth2.googleapis.com/token, as google-auth has it, also for anothertoken_uri.
- client_email¶
email = provider.client_email
The email of the service account.
- async fetch() Pyjo_GCP_Credentials[source]¶
credentials = await provider.fetch()
The self-signed JWT, or the access token of the grant.
- classmethod from_info(info: Mapping[str, Any], **kwargs: Any) Self[source]¶
provider = ServiceAccount.from_info(info) provider = ServiceAccount.from_info(info, scopes=scopes, ua=ua)
A new provider of the JSON object of a file of the type
service_account, withprivate_key_id,project_idanduniverse_domainof the file, and the arguments over them, or aPyjo.Exceptionof a file withoutclient_email,private_keyortoken_uri, as google-auth requires them.
- key¶
key = provider.key
The private key of the service account, a
Pyjo.GCP.RSAobject.
- private_key_id¶
key_id = provider.private_key_id
The ID of the key,
kidof the JWT, orNone.
- project¶
project = provider.project
The project of the key, or
None.
- quota_project¶
project = provider.quota_project
The quota project of the credentials, or
None.
- scopes¶
scopes = provider.scopes
The scopes of the token,
https://www.googleapis.com/auth/cloud-platformby default.
- self_signed¶
boolean = provider.self_signed
Whether the token is a self-signed JWT of AIP-4111, rather than the access token of the grant, false by default, and true for a key of another universe domain than
googleapis.com. Asubjecthas the grant always.
- subject¶
email = provider.subject
The email of a user that the service account acts as, of the domain-wide delegation of Google Workspace, or
None.
- token_uri¶
url = provider.token_uri
The token endpoint of OAuth 2.0 of the grant, of the key, or
https://oauth2.googleapis.com/token.
- universe_domain¶
domain = provider.universe_domain
The universe domain of the key, or
None.
- Pyjo.GCP.Credentials.ServiceAccount.TOKEN_URI = 'https://oauth2.googleapis.com/token'¶
The token endpoint of OAuth 2.0 of Google, the audience of the grant of the key.