google.auth package¶
Google Auth Library for Python.
- default(scopes=None,request=None,quota_project_id=None,default_scopes=None)[source]¶
Gets the default credentials for the current environment.
Application Default Credentials provides an easy way to obtaincredentials to call Google APIs for server-to-server or local applications.This function acquires credentials from the environment in the followingorder:
If the environment variable
GOOGLE_APPLICATION_CREDENTIALS
is setto the path of a valid service account JSON private key file, then it isloaded and returned. The project ID returned is the project ID definedin the service account file if available (some older files do notcontain project ID information).If the environment variable is set to the path of a valid externalaccount JSON configuration file (workload identity federation), then theconfiguration file is used to determine and retrieve the externalcredentials from the current environment (AWS, Azure, etc).These will then be exchanged for Google access tokens via the Google STSendpoint.The project ID returned in this case is the one corresponding to theunderlying workload identity pool resource if determinable.
If the environment variable is set to the path of a valid GDCH serviceaccount JSON file (Google Distributed Cloud Hosted), then a GDCHcredential will be returned. The project ID returned is the projectspecified in the JSON file.
If theGoogle Cloud SDK is installed and has application defaultcredentials set they are loaded and returned.
To enable application default credentials with the Cloud SDK run:
gcloudauthapplication-defaultlogin
If the Cloud SDK has an active project, the project ID is returned. Theactive project can be set using:
gcloudconfigsetproject
If the application is running in theApp Engine standard environment(first generation) then the credentials and project ID from theApp Identity Service are used.
If the application is running inCompute Engine orCloud Run ortheApp Engine flexible environment or theApp Engine standardenvironment (second generation) then the credentials and project IDare obtained from theMetadata Service.
If no credentials are found,
DefaultCredentialsError
will be raised.
Example:
importgoogle.authcredentials,project_id=google.auth.default()
- Parameters:
scopes (
Sequence
str
) – The list of scopes for the credentials. Ifspecified, the credentials will automatically be scoped ifnecessary.request (
Optional
google.auth.transport.Request
) – An object used to makeHTTP requests. This is used to either detect whether the applicationis running on Compute Engine or to determine the associated projectID for a workload identity pool resource (external accountcredentials). If not specified, then it will either use the standardlibrary http client to make requests for Compute Engine credentialsor a google.auth.transport.requests.Request client for externalaccount credentials.quota_project_id (
Optional
str
) – The project ID used forquota and billing.default_scopes (
Optional
Sequence
str
) – Default scopes passed by aGoogle client library. Use ‘scopes’ for user-defined scopes.
- Returns:
the current environment’s credentials and project ID. Project IDmay be None, which indicates that the Project ID could not beascertained from the environment.
- Return type:
- Raises:
DefaultCredentialsError – If no credentials were found, or if the credentials found were invalid.
- load_credentials_from_file(filename,scopes=None,default_scopes=None,quota_project_id=None,request=None)[source]¶
Loads Google credentials from a file.
The credentials file must be a service account key, stored authorizeduser credentials, external account credentials, or impersonated serviceaccount credentials.
Warning
Important: If you accept a credential configuration (credential JSON/File/Stream)from an external source for authentication to Google Cloud Platform, you mustvalidate it before providing it to any Google API or client library. Providing anunvalidated credential configuration to Google APIs or libraries can compromisethe security of your systems and data. For more information, refer toValidate credential configurations from external sources.
- Parameters:
filename (str) – The full path to the credentials file.
scopes (
Optional
Sequence
str
) – The list of scopes for the credentials. Ifspecified, the credentials will automatically be scoped ifnecessarydefault_scopes (
Optional
Sequence
str
) – Default scopes passed by aGoogle client library. Use ‘scopes’ for user-defined scopes.quota_project_id (
Optional
str
) – The project ID used forquota and billing.request (
Optional
google.auth.transport.Request
) – An object used to makeHTTP requests. This is used to determine the associated project IDfor a workload identity pool resource (external account credentials).If not specified, then it will use agoogle.auth.transport.requests.Request client to make requests.
- Returns:
- Loaded
credentials and the project ID. Authorized user credentials do nothave the project ID information. External account credentials projectIDs may not always be determined.
- Return type:
- Raises:
google.auth.exceptions.DefaultCredentialsError – if the file is in the wrong format or is missing.
- load_credentials_from_dict(info,scopes=None,default_scopes=None,quota_project_id=None,request=None)[source]¶
Loads Google credentials from a dict.
The credentials file must be a service account key, stored authorizeduser credentials, external account credentials, or impersonated serviceaccount credentials.
Warning
Important: If you accept a credential configuration (credential JSON/File/Stream)from an external source for authentication to Google Cloud Platform, you mustvalidate it before providing it to any Google API or client library. Providing anunvalidated credential configuration to Google APIs or libraries can compromisethe security of your systems and data. For more information, refer toValidate credential configurations from external sources.
- Parameters:
info (
Dict
str
,Any
) – A dict object containing the credentialsscopes (
Optional
Sequence
str
) – The list of scopes for the credentials. Ifspecified, the credentials will automatically be scoped ifnecessarydefault_scopes (
Optional
Sequence
str
) – Default scopes passed by aGoogle client library. Use ‘scopes’ for user-defined scopes.quota_project_id (
Optional
str
) – The project ID used forquota and billing.request (
Optional
google.auth.transport.Request
) – An object used to makeHTTP requests. This is used to determine the associated project IDfor a workload identity pool resource (external account credentials).If not specified, then it will use agoogle.auth.transport.requests.Request client to make requests.
- Returns:
- Loaded
credentials and the project ID. Authorized user credentials do nothave the project ID information. External account credentials projectIDs may not always be determined.
- Return type:
- Raises:
google.auth.exceptions.DefaultCredentialsError – if the file is in the wrong format or is missing.
Subpackages¶
- google.auth.compute_engine package
Credentials
Credentials.refresh()
Credentials.service_account_email
Credentials.requires_scopes
Credentials.universe_domain
Credentials.get_cred_info()
Credentials.with_quota_project()
Credentials.with_scopes()
Credentials.with_universe_domain()
Credentials.apply()
Credentials.before_request()
Credentials.default_scopes
Credentials.expired
Credentials.has_scopes()
Credentials.quota_project_id
Credentials.scopes
Credentials.token_state
Credentials.valid
Credentials.expiry
IDTokenCredentials
IDTokenCredentials.with_target_audience()
IDTokenCredentials.with_quota_project()
IDTokenCredentials.with_token_uri()
IDTokenCredentials.apply()
IDTokenCredentials.before_request()
IDTokenCredentials.expired
IDTokenCredentials.get_cred_info()
IDTokenCredentials.quota_project_id
IDTokenCredentials.token_state
IDTokenCredentials.universe_domain
IDTokenCredentials.valid
IDTokenCredentials.expiry
IDTokenCredentials.refresh()
IDTokenCredentials.signer
IDTokenCredentials.sign_bytes()
IDTokenCredentials.service_account_email
IDTokenCredentials.signer_email
detect_gce_residency_linux()
- Submodules
- google.auth.crypt package
- google.auth.transport package
Submodules¶
- google.auth.app_engine module
Signer
get_project_id()
Credentials
Credentials.refresh()
Credentials.service_account_email
Credentials.requires_scopes
Credentials.with_scopes()
Credentials.with_quota_project()
Credentials.sign_bytes()
Credentials.signer_email
Credentials.signer
Credentials.apply()
Credentials.before_request()
Credentials.default_scopes
Credentials.expired
Credentials.get_cred_info()
Credentials.has_scopes()
Credentials.quota_project_id
Credentials.scopes
Credentials.token_state
Credentials.universe_domain
Credentials.valid
Credentials.expiry
- google.auth.aws module
RequestSigner
AwsSecurityCredentials
AwsSecurityCredentialsSupplier
Credentials
Credentials.retrieve_subject_token()
Credentials.apply()
Credentials.before_request()
Credentials.default_scopes
Credentials.expired
Credentials.from_info()
Credentials.get_cred_info()
Credentials.get_project_id()
Credentials.has_scopes()
Credentials.info
Credentials.is_user
Credentials.is_workforce_pool
Credentials.project_number
Credentials.quota_project_id
Credentials.refresh()
Credentials.requires_scopes
Credentials.scopes
Credentials.service_account_email
Credentials.token_info_url
Credentials.token_state
Credentials.universe_domain
Credentials.valid
Credentials.with_quota_project()
Credentials.with_scopes()
Credentials.with_token_uri()
Credentials.with_universe_domain()
Credentials.expiry
Credentials.from_file()
- google.auth.credentials module
Credentials
CredentialsWithQuotaProject
CredentialsWithQuotaProject.with_quota_project()
CredentialsWithQuotaProject.apply()
CredentialsWithQuotaProject.before_request()
CredentialsWithQuotaProject.expired
CredentialsWithQuotaProject.get_cred_info()
CredentialsWithQuotaProject.quota_project_id
CredentialsWithQuotaProject.refresh()
CredentialsWithQuotaProject.token_state
CredentialsWithQuotaProject.universe_domain
CredentialsWithQuotaProject.valid
CredentialsWithQuotaProject.expiry
CredentialsWithTokenUri
CredentialsWithTokenUri.with_token_uri()
CredentialsWithTokenUri.apply()
CredentialsWithTokenUri.before_request()
CredentialsWithTokenUri.expired
CredentialsWithTokenUri.get_cred_info()
CredentialsWithTokenUri.quota_project_id
CredentialsWithTokenUri.refresh()
CredentialsWithTokenUri.token_state
CredentialsWithTokenUri.universe_domain
CredentialsWithTokenUri.valid
CredentialsWithTokenUri.expiry
CredentialsWithUniverseDomain
CredentialsWithUniverseDomain.with_universe_domain()
CredentialsWithUniverseDomain.apply()
CredentialsWithUniverseDomain.before_request()
CredentialsWithUniverseDomain.expired
CredentialsWithUniverseDomain.get_cred_info()
CredentialsWithUniverseDomain.quota_project_id
CredentialsWithUniverseDomain.refresh()
CredentialsWithUniverseDomain.token_state
CredentialsWithUniverseDomain.universe_domain
CredentialsWithUniverseDomain.valid
CredentialsWithUniverseDomain.expiry
AnonymousCredentials
AnonymousCredentials.expired
AnonymousCredentials.valid
AnonymousCredentials.refresh()
AnonymousCredentials.apply()
AnonymousCredentials.before_request()
AnonymousCredentials.get_cred_info()
AnonymousCredentials.quota_project_id
AnonymousCredentials.token_state
AnonymousCredentials.universe_domain
AnonymousCredentials.expiry
ReadOnlyScoped
Scoped
with_scopes_if_required()
Signing
TokenState
- google.auth.credentials_async module
Credentials
CredentialsWithQuotaProject
CredentialsWithQuotaProject.apply()
CredentialsWithQuotaProject.before_request()
CredentialsWithQuotaProject.expired
CredentialsWithQuotaProject.get_cred_info()
CredentialsWithQuotaProject.quota_project_id
CredentialsWithQuotaProject.refresh()
CredentialsWithQuotaProject.token_state
CredentialsWithQuotaProject.universe_domain
CredentialsWithQuotaProject.valid
CredentialsWithQuotaProject.with_quota_project()
CredentialsWithQuotaProject.expiry
AnonymousCredentials
AnonymousCredentials.apply()
AnonymousCredentials.before_request()
AnonymousCredentials.expired
AnonymousCredentials.get_cred_info()
AnonymousCredentials.quota_project_id
AnonymousCredentials.refresh()
AnonymousCredentials.token_state
AnonymousCredentials.universe_domain
AnonymousCredentials.valid
AnonymousCredentials.expiry
ReadOnlyScoped
Scoped
with_scopes_if_required()
Signing
- google.auth.downscoped module
- google.auth.environment_vars module
- google.auth.exceptions module
- google.auth.external_account module
SupplierContext
Credentials
Credentials.info
Credentials.service_account_email
Credentials.is_user
Credentials.is_workforce_pool
Credentials.requires_scopes
Credentials.project_number
Credentials.token_info_url
Credentials.get_cred_info()
Credentials.with_scopes()
Credentials.retrieve_subject_token()
Credentials.get_project_id()
Credentials.refresh()
Credentials.with_quota_project()
Credentials.with_token_uri()
Credentials.with_universe_domain()
Credentials.apply()
Credentials.before_request()
Credentials.default_scopes
Credentials.expired
Credentials.from_info()
Credentials.has_scopes()
Credentials.quota_project_id
Credentials.scopes
Credentials.token_state
Credentials.universe_domain
Credentials.valid
Credentials.expiry
Credentials.from_file()
- google.auth.iam module
- google.auth.identity_pool module
SubjectTokenSupplier
Credentials
Credentials.retrieve_subject_token()
Credentials.apply()
Credentials.before_request()
Credentials.default_scopes
Credentials.expired
Credentials.get_cred_info()
Credentials.get_project_id()
Credentials.has_scopes()
Credentials.info
Credentials.is_user
Credentials.is_workforce_pool
Credentials.project_number
Credentials.quota_project_id
Credentials.refresh()
Credentials.requires_scopes
Credentials.scopes
Credentials.service_account_email
Credentials.token_info_url
Credentials.token_state
Credentials.universe_domain
Credentials.valid
Credentials.with_quota_project()
Credentials.with_scopes()
Credentials.with_token_uri()
Credentials.with_universe_domain()
Credentials.expiry
Credentials.from_info()
Credentials.from_file()
- google.auth.impersonated_credentials module
Credentials
Credentials.expiry
Credentials.refresh()
Credentials.sign_bytes()
Credentials.signer_email
Credentials.signer
Credentials.requires_scopes
Credentials.get_cred_info()
Credentials.with_quota_project()
Credentials.with_scopes()
Credentials.from_impersonated_service_account_info()
Credentials.apply()
Credentials.before_request()
Credentials.default_scopes
Credentials.expired
Credentials.has_scopes()
Credentials.quota_project_id
Credentials.scopes
Credentials.token_state
Credentials.universe_domain
Credentials.valid
IDTokenCredentials
IDTokenCredentials.with_quota_project()
IDTokenCredentials.refresh()
IDTokenCredentials.apply()
IDTokenCredentials.before_request()
IDTokenCredentials.expired
IDTokenCredentials.get_cred_info()
IDTokenCredentials.quota_project_id
IDTokenCredentials.token_state
IDTokenCredentials.universe_domain
IDTokenCredentials.valid
IDTokenCredentials.expiry
- google.auth.jwt module
encode()
decode_header()
decode()
Credentials
Credentials.from_service_account_info()
Credentials.from_service_account_file()
Credentials.from_signing_credentials()
Credentials.with_claims()
Credentials.with_quota_project()
Credentials.refresh()
Credentials.sign_bytes()
Credentials.signer_email
Credentials.signer
Credentials.additional_claims
Credentials.apply()
Credentials.before_request()
Credentials.expired
Credentials.get_cred_info()
Credentials.quota_project_id
Credentials.token_state
Credentials.universe_domain
Credentials.valid
Credentials.expiry
OnDemandCredentials
OnDemandCredentials.from_service_account_info()
OnDemandCredentials.from_service_account_file()
OnDemandCredentials.from_signing_credentials()
OnDemandCredentials.with_claims()
OnDemandCredentials.with_quota_project()
OnDemandCredentials.valid
OnDemandCredentials.refresh()
OnDemandCredentials.before_request()
OnDemandCredentials.sign_bytes()
OnDemandCredentials.signer_email
OnDemandCredentials.signer
OnDemandCredentials.apply()
OnDemandCredentials.expired
OnDemandCredentials.get_cred_info()
OnDemandCredentials.quota_project_id
OnDemandCredentials.token_state
OnDemandCredentials.universe_domain
OnDemandCredentials.expiry
- google.auth.jwt_async module
encode()
decode()
Credentials
Credentials.additional_claims
Credentials.apply()
Credentials.before_request()
Credentials.expired
Credentials.from_service_account_file()
Credentials.from_service_account_info()
Credentials.from_signing_credentials()
Credentials.get_cred_info()
Credentials.quota_project_id
Credentials.refresh()
Credentials.sign_bytes()
Credentials.signer
Credentials.signer_email
Credentials.token_state
Credentials.universe_domain
Credentials.valid
Credentials.with_claims()
Credentials.with_quota_project()
Credentials.expiry
OnDemandCredentials
OnDemandCredentials.apply()
OnDemandCredentials.before_request()
OnDemandCredentials.expired
OnDemandCredentials.from_service_account_file()
OnDemandCredentials.from_service_account_info()
OnDemandCredentials.from_signing_credentials()
OnDemandCredentials.get_cred_info()
OnDemandCredentials.quota_project_id
OnDemandCredentials.refresh()
OnDemandCredentials.sign_bytes()
OnDemandCredentials.signer
OnDemandCredentials.signer_email
OnDemandCredentials.token_state
OnDemandCredentials.universe_domain
OnDemandCredentials.valid
OnDemandCredentials.with_claims()
OnDemandCredentials.with_quota_project()
OnDemandCredentials.expiry