OAuth 2.0 Credentials.
This module provides credentials based on OAuth 2.0 access and refresh tokens. These credentials usually access resources on behalf of a user (resource owner).
Specifically, this is intended to use access tokens acquired using the Authorization Code grant and can refresh those tokens using a optional refresh token.
Obtaining the initial access and refresh token is outside of the scope of this module. Consult rfc6749 section 4.1 for complete details on the Authorization Code grant flow.
Bases: google.auth.credentials.ReadOnlyScoped
, google.auth.credentials.CredentialsWithQuotaProject
Credentials using OAuth 2.0 access and refresh tokens.
The credentials are considered immutable except the tokens and the token expiry, which are updated after refresh. If you want to modify the quota project, use with_quota_project()
or
credentials = credentials.with_quota_project('myproject-123')
Reauth is disabled by default. To enable reauth, set the enable_reauth_refresh parameter to True in the constructor. Note that reauth feature is intended for gcloud to use only. If reauth is enabled, pyu2f dependency has to be installed in order to use security key reauth feature. Dependency can be installed via pip install pyu2f or pip install google-auth[reauth].
token (Optional(str)) – The OAuth 2.0 access token. Can be None if refresh information is provided.
refresh_token (str) – The OAuth 2.0 refresh token. If specified, credentials can be refreshed.
id_token (str) – The Open ID Connect ID Token.
token_uri (str) – The OAuth 2.0 authorization server’s token endpoint URI. Must be specified for refresh, can be left as None if the token can not be refreshed.
client_id (str) – The OAuth 2.0 client ID. Must be specified for refresh, can be left as None if the token can not be refreshed.
client_secret (str) – The OAuth 2.0 client secret. Must be specified for refresh, can be left as None if the token can not be refreshed.
scopes (Sequence
str
) – The scopes used to obtain authorization. This parameter is used by has_scopes()
. OAuth 2.0 credentials can not request additional scopes after authorization. The scopes must be derivable from the refresh token if refresh information is provided (e.g. The refresh token scopes are a superset of this or contain a wild card scope like ‘https://www.googleapis.com/auth/any-api’).
default_scopes (Sequence
str
) – Default scopes passed by a Google client library. Use ‘scopes’ for user-defined scopes.
quota_project_id (Optional
str
) – The project ID used for quota and billing. This project may be different from the project used to create the credentials.
refresh_handler (Optional
Callable
google.auth.transport.Request
Sequence
str
, str
datetime
) – A callable which takes in the HTTP request callable and the list of OAuth scopes and when called returns an access token string for the requested scopes and its expiry datetime. This is useful when no refresh tokens are provided and tokens are obtained by calling some external process on demand. It is particularly useful for retrieving downscoped tokens from a token broker.
enable_reauth_refresh (Optional
bool
) – Whether reauth refresh flow should be used. This flag is for gcloud to use only.
granted_scopes (Optional
Sequence
str
) – The scopes that were consented/granted by the user. This could be different from the requested scopes and it could be empty if granted and requested scopes were same.
trust_boundary (str) – String representation of trust boundary meta.
universe_domain (Optional
str
) – The universe domain. The default universe domain is googleapis.com.
account (Optional
str
) – The account associated with the credential.
When the token expires and is no longer valid. If this is None, the token is assumed to never expire.
The OAuth 2.0 permission scopes that were granted by the user.
The Open ID Connect ID Token.
Depending on the authorization server and the scopes requested, this may be populated when credentials are obtained and updated when refresh()
is called. This token is a JWT. It can be verified and decoded using google.oauth2.id_token.verify_oauth2_token()
.
OAuth 2.0 credentials have their scopes set when the initial token is requested and can not be changed.
False
Returns the refresh handler if available.
The user account associated with the credential. If the account is unknown an empty string is returned.
The credential information JSON.
The credential information will be added to auth related error messages by client library.
Returns a copy of these credentials with a modified quota project.
quota_project_id (str) – The project to use for quota and billing purposes
A new credentials instance.
Returns a copy of these credentials with a modified token uri.
token_uri (str) – The uri to use for fetching/exchanging tokens
A new credentials instance.
Returns a copy of these credentials with a modified account.
account (str) – The account to set
A new credentials instance.
Returns a copy of these credentials with a modified universe domain.
universe_domain (str) – The universe domain to use
A new credentials instance.
Refreshes the access token.
request (google.auth.transport.Request) – The object used to make HTTP requests.
google.auth.exceptions.RefreshError – If the credentials could not be refreshed.
Creates a Credentials instance from parsed authorized user info.
credentials.
ValueError – If the info is not in the expected format.
Creates a Credentials instance from an authorized user json file.
credentials.
ValueError – If the file is not in the expected format.
Utility function that creates a JSON representation of a Credentials object.
Apply the token to the authentication header.
Performs credential-specific before request logic.
Refreshes the credentials if necessary, then calls apply()
to apply the token to the authentication header.
request (google.auth.transport.Request) – The object used to make HTTP requests.
method (str) – The request’s HTTP method or the RPC method being invoked.
url (str) – The request’s URI or the RPC service’s URI.
headers (Mapping) – The request’s headers.
Checks if the credentials are expired.
Note that credentials can be invalid but not expired because Credentials with expiry
set to None is considered to never expire.
Deprecated since version v2.24.0: Prefer checking token_state
instead.
Checks if the credentials have the given scopes.
Project to use for quota and billing purposes.
See :obj:`TokenState
The universe domain value.
Checks the validity of the credentials.
This is True if the credentials have a token
and the token is not expired
.
Deprecated since version v2.24.0: Prefer checking token_state
instead.
Bases: google.auth.credentials.CredentialsWithQuotaProject
Access token credentials for user account.
Obtain the access token for a given user account or the current active user account with the gcloud auth print-access-token
command.
Create a new instance with the given account.
account (str) – Account to get the access token for.
credentials with the given account.
Returns a copy of these credentials with a modified quota project.
quota_project_id (str) – The project to use for quota and billing purposes
A new credentials instance.
Apply the token to the authentication header.
Checks if the credentials are expired.
Note that credentials can be invalid but not expired because Credentials with expiry
set to None is considered to never expire.
Deprecated since version v2.24.0: Prefer checking token_state
instead.
The credential information JSON.
The credential information will be added to auth related error messages by client library.
Project to use for quota and billing purposes.
Refreshes the access token.
request (google.auth.transport.Request) – This argument is required by the base class interface but not used in this implementation, so just set it to None.
google.auth.exceptions.UserAccessTokenError – If the access token refresh failed.
See :obj:`TokenState
The universe domain value.
Checks the validity of the credentials.
This is True if the credentials have a token
and the token is not expired
.
Deprecated since version v2.24.0: Prefer checking token_state
instead.
When the token expires and is no longer valid. If this is None, the token is assumed to never expire.
Performs credential-specific before request logic.
Refreshes the credentials if necessary, then calls apply()
to apply the token to the authentication header.
request (google.auth.transport.Request) – The object used to make HTTP requests.
method (str) – The request’s HTTP method or the RPC method being invoked.
url (str) – The request’s URI or the RPC service’s URI.
headers (Mapping) – The request’s headers.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4