pittgoogle.auth
Classes to manage authentication with Google Cloud.
Note
To authenticate, you must have completed one of the setup options described in Authentication. The recommendation is to use a service account and set environment variables. In that case, you will not need to call this module directly.
|
Credentials for authenticating with a Google Cloud project. |
- class pittgoogle.auth.Auth(GOOGLE_CLOUD_PROJECT: str | None = NOTHING, GOOGLE_APPLICATION_CREDENTIALS: str | None = NOTHING, OAUTH_CLIENT_ID: str | None = NOTHING, OAUTH_CLIENT_SECRET: str | None = NOTHING)[source]
Credentials for authenticating with a Google Cloud project.
This class provides methods to load credentials from either a service account key file or an OAuth2 session. To authenticate, you must have completed one of the setup options described in Authentication.
In typical use cases, the following arguments are set as environment variables instead of being passed to Auth explicitly.
- Parameters:
GOOGLE_CLOUD_PROJECT (str, optional) – The project ID of the Google Cloud project to connect to.
GOOGLE_APPLICATION_CREDENTIALS (str, optional) – The path to a keyfile containing service account credentials. Either this or the OAUTH_CLIENT_* settings are required for successful authentication.
OAUTH_CLIENT_ID (str, optional) – The client ID for an OAuth2 connection. Either this and OAUTH_CLIENT_SECRET, or the GOOGLE_APPLICATION_CREDENTIALS setting, are required for successful authentication.
OAUTH_CLIENT_SECRET (str, optional) – The client secret for an OAuth2 connection. Either this and OAUTH_CLIENT_ID, or the GOOGLE_APPLICATION_CREDENTIALS setting, are required for successful authentication.
Example
The basic call is:
myauth = pittgoogle.Auth()
This will load authentication settings from your environment variables. You can override this behavior with keyword arguments. This does not automatically load the credentials. To do that, request them explicitly:
myauth.credentials
It will first look for a service account key file, then fallback to OAuth2.
- GOOGLE_APPLICATION_CREDENTIALS: str | None
The path to a keyfile containing service account credentials.
- GOOGLE_CLOUD_PROJECT: str | None
The project ID of the Google Cloud project to connect to.
- OAUTH_CLIENT_ID: str | None
The client ID for an OAuth2 connection.
- OAUTH_CLIENT_SECRET: str | None
The client secret for an OAuth2 connection.
- property credentials: Credentials | Credentials
Credentials, loaded from a service account key file or an OAuth2 session.
- property oauth2: OAuth2Session
requests_oauthlib.OAuth2Session connected to the Google Cloud project.