Class GoogleCredentials (1.36.0)
Stay organized with collections
Save and categorize content based on your preferences.
publicclass GoogleCredentialsextendsOAuth2CredentialsimplementsQuotaProjectIdProviderBase type for credentials for authorizing calls to Google APIs using OAuth2.
Implements
QuotaProjectIdProviderInherited Members
Static Methods
create(AccessToken accessToken)
publicstaticGoogleCredentialscreate(AccessTokenaccessToken)Returns the credentials instance from the given access token.
| Parameter | |
|---|---|
| Name | Description |
accessToken |
AccessToken the access token |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
the credentials instance |
create(String universeDomain, AccessToken accessToken)
publicstaticGoogleCredentialscreate(StringuniverseDomain,AccessTokenaccessToken)Returns the credentials instance from the given access token and universe domain.
| Parameters | |
|---|---|
| Name | Description |
universeDomain |
String the universe domain |
accessToken |
AccessToken the access token |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
the credentials instance |
fromStream(InputStream credentialsStream)
publicstaticGoogleCredentialsfromStream(InputStreamcredentialsStream)Returns credentials defined by a JSON file stream.
The stream can contain a Service Account key file in JSON format from the Google Developers Console or a stored user credential using the format supported by the Cloud SDK.
Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source for authentication to Google Cloud Platform, you must validate it before providing it to any Google API or library. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. For more information, refer to {@link documentation}.
| Parameter | |
|---|---|
| Name | Description |
credentialsStream |
InputStream the stream with the credential definition. |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
the credential defined by the credentialsStream. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
if the credential cannot be created from the stream. |
fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory)
publicstaticGoogleCredentialsfromStream(InputStreamcredentialsStream,HttpTransportFactorytransportFactory)Returns credentials defined by a JSON file stream.
The stream can contain a Service Account key file in JSON format from the Google Developers Console or a stored user credential using the format supported by the Cloud SDK.
Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source for authentication to Google Cloud Platform, you must validate it before providing it to any Google API or library. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. For more information, refer to {@link documentation}.
| Parameters | |
|---|---|
| Name | Description |
credentialsStream |
InputStream the stream with the credential definition. |
transportFactory |
HttpTransportFactory HTTP transport factory, creates the transport used to get access tokens. |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
the credential defined by the credentialsStream. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
if the credential cannot be created from the stream. |
getApplicationDefault()
publicstaticGoogleCredentialsgetApplicationDefault()Returns the Application Default Credentials.
Returns the Application Default Credentials which are used to identify and authorize the whole application. The following are searched (in order) to find the Application Default Credentials:
- Credentials file pointed to by the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable - Credentials provided by the Google Cloud SDK.
gcloud auth application-default loginfor user account credentials.gcloud auth application-default login --impersonate-service-accountfor impersonated service account credentials.
- Google App Engine built-in credentials
- Google Cloud Shell built-in credentials
- Google Compute Engine built-in credentials
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
the credentials instance. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
if the credentials cannot be created in the current environment. |
getApplicationDefault(HttpTransportFactory transportFactory)
publicstaticGoogleCredentialsgetApplicationDefault(HttpTransportFactorytransportFactory)Returns the Application Default Credentials.
Returns the Application Default Credentials which are used to identify and authorize the whole application. The following are searched (in order) to find the Application Default Credentials:
- Credentials file pointed to by the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable - Credentials provided by the Google Cloud SDK
gcloud auth application-default logincommand - Google App Engine built-in credentials
- Google Cloud Shell built-in credentials
- Google Compute Engine built-in credentials
| Parameter | |
|---|---|
| Name | Description |
transportFactory |
HttpTransportFactory HTTP transport factory, creates the transport used to get access tokens. |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
the credentials instance. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
if the credentials cannot be created in the current environment. |
newBuilder()
publicstaticGoogleCredentials.BuildernewBuilder()| Returns | |
|---|---|
| Type | Description |
GoogleCredentials.Builder |
|
Constructors
GoogleCredentials()
protectedGoogleCredentials()Default constructor.
GoogleCredentials(AccessToken accessToken)
publicGoogleCredentials(AccessTokenaccessToken)Constructor with explicit access token.
| Parameter | |
|---|---|
| Name | Description |
accessToken |
AccessToken initial or temporary access token |
GoogleCredentials(AccessToken accessToken, String quotaProjectId)
protectedGoogleCredentials(AccessTokenaccessToken,StringquotaProjectId)Constructor with an explicit access token and quotaProjectId.
Deprecated, please use the GoogleCredentials#GoogleCredentials(Builder) constructor whenever possible.
| Parameters | |
|---|---|
| Name | Description |
accessToken |
AccessToken initial or temporary access token |
quotaProjectId |
String a quotaProjectId, a project id to be used for billing purposes |
GoogleCredentials(AccessToken accessToken, Duration refreshMargin, Duration expirationMargin)
protectedGoogleCredentials(AccessTokenaccessToken,DurationrefreshMargin,DurationexpirationMargin)Constructor with explicit access token and refresh margins.
Deprecated, please use the GoogleCredentials#GoogleCredentials(Builder) constructor whenever possible.
| Parameters | |
|---|---|
| Name | Description |
accessToken |
AccessToken initial or temporary access token |
refreshMargin |
Duration |
expirationMargin |
Duration |
GoogleCredentials(GoogleCredentials.Builder builder)
protectedGoogleCredentials(GoogleCredentials.Builderbuilder)Constructor that relies on a Builder to provide all the necessary field values for initialization.
| Parameter | |
|---|---|
| Name | Description |
builder |
GoogleCredentials.Builder an instance of a builder |
Fields
quotaProjectId
protectedfinalStringquotaProjectId| Field Value | |
|---|---|
| Type | Description |
String |
|
Methods
createDelegated(String user)
publicGoogleCredentialscreateDelegated(Stringuser)If the credentials support domain-wide delegation, creates a copy of the identity so that it impersonates the specified user; otherwise, returns the same instance.
| Parameter | |
|---|---|
| Name | Description |
user |
String User to impersonate. |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
GoogleCredentials with a delegated user. |
createScoped(String[] scopes)
publicGoogleCredentialscreateScoped(String[]scopes)If the credentials support scopes, creates a copy of the identity with the specified scopes; otherwise, returns the same instance.
| Parameter | |
|---|---|
| Name | Description |
scopes |
String[]Collection of scopes to request. |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
GoogleCredentials with requested scopes. |
createScoped(Collection<String> scopes)
publicGoogleCredentialscreateScoped(Collection<String>scopes)If the credentials support scopes, creates a copy of the identity with the specified scopes, invalidates the existing scoped access token; otherwise, return the same instance.
| Parameter | |
|---|---|
| Name | Description |
scopes |
Collection<String>Collection of scopes to request. |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
GoogleCredentials with requested scopes. |
createScoped(Collection<String> scopes, Collection<String> defaultScopes)
publicGoogleCredentialscreateScoped(Collection<String>scopes,Collection<String>defaultScopes)If the credentials support scopes, creates a copy of the identity with the specified scopes and default scopes; otherwise, returns the same instance. This is mainly used by client libraries.
| Parameters | |
|---|---|
| Name | Description |
scopes |
Collection<String>Collection of scopes to request. |
defaultScopes |
Collection<String>Collection of default scopes to request. |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
GoogleCredentials with requested scopes. |
createScopedRequired()
publicbooleancreateScopedRequired()Indicates whether the credentials require scopes to be specified via a call to GoogleCredentials#createScoped before use.
| Returns | |
|---|---|
| Type | Description |
boolean |
Whether the credentials require scopes to be specified. |
createWithCustomRetryStrategy(boolean defaultRetriesEnabled)
publicGoogleCredentialscreateWithCustomRetryStrategy(booleandefaultRetriesEnabled)If the credentials support automatic retries, creates a copy of the identity with the provided retry strategy
| Parameter | |
|---|---|
| Name | Description |
defaultRetriesEnabled |
boolean a flag enabling or disabling default retries |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
GoogleCredentials with the new default retries configuration. |
createWithQuotaProject(String quotaProject)
publicGoogleCredentialscreateWithQuotaProject(StringquotaProject)Creates a credential with the provided quota project.
| Parameter | |
|---|---|
| Name | Description |
quotaProject |
String the quota project to set on the credential |
| Returns | |
|---|---|
| Type | Description |
GoogleCredentials |
credential with the provided quota project |
equals(Object obj)
publicbooleanequals(Objectobj)| Parameter | |
|---|---|
| Name | Description |
obj |
Object |
| Returns | |
|---|---|
| Type | Description |
boolean |
|
getAdditionalHeaders()
protectedMap<String,List<String>>getAdditionalHeaders()Provide additional headers to return as request metadata.
| Returns | |
|---|---|
| Type | Description |
Map<String,List<String>> |
|
getQuotaProjectId()
publicStringgetQuotaProjectId()| Returns | |
|---|---|
| Type | Description |
String |
|
getUniverseDomain()
publicStringgetUniverseDomain()Gets the universe domain for the credential.
| Returns | |
|---|---|
| Type | Description |
String |
An explicit universe domain if it was explicitly provided, invokes the super implementation otherwise |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
hashCode()
publicinthashCode()| Returns | |
|---|---|
| Type | Description |
int |
|
isExplicitUniverseDomain()
protectedbooleanisExplicitUniverseDomain()Gets the flag indicating whether universeDomain was explicitly set by the developer.
If subclass has a requirement to give priority to developer-set universeDomain, this property must be used to check if the universeDomain value was provided by the user. It could be a default otherwise.
| Returns | |
|---|---|
| Type | Description |
boolean |
true if universeDomain value was provided by the developer, false otherwise |
toBuilder()
publicGoogleCredentials.BuildertoBuilder()| Returns | |
|---|---|
| Type | Description |
GoogleCredentials.Builder |
|
toString()
publicStringtoString()| Returns | |
|---|---|
| Type | Description |
String |
|
toStringHelper()
protectedMoreObjects.ToStringHelpertoStringHelper()A helper for overriding the toString() method. This allows inheritance of super class fields. Extending classes can override this implementation and call super implementation and add more fields. Same cannot be done with overriding the toString() directly.
| Returns | |
|---|---|
| Type | Description |
com.google.common.base.MoreObjects.ToStringHelper |
an instance of the ToStringHelper that has public fields added |