public static GoogleCredentials fromStream(InputStream credentialsStream)
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
InputStreamthe stream with the credential definition.
public static GoogleCredentials fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory)
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
InputStreamthe stream with the credential definition.
transportFactory
HttpTransportFactoryHTTP transport factory, creates the transport used to get access tokens.
if the credential cannot be created from the stream.
getApplicationDefault()
public static GoogleCredentials getApplicationDefault()
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_CREDENTIALS environment variable
Credentials provided by the Google Cloud SDK.
gcloud auth application-default login for user account credentials.
gcloud auth application-default login --impersonate-service-account for impersonated service account credentials.
public static GoogleCredentials getApplicationDefault(HttpTransportFactory transportFactory)
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_CREDENTIALS environment variable
Credentials provided by the Google Cloud SDK gcloud auth application-default login command
Google App Engine built-in credentials
Google Cloud Shell built-in credentials
Google Compute Engine built-in credentials
Parameter
Name
Description
transportFactory
HttpTransportFactoryHTTP transport factory, creates the transport used to get access tokens.
public GoogleCredentials createDelegated(String user)
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.
public GoogleCredentials createScoped(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.
public GoogleCredentials createScoped(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.
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.
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