public class GoogleCredentials extends OAuth2Credentials implements QuotaProjectIdProvider
| Modifier and Type | Class and Description |
|---|---|
static class |
GoogleCredentials.Builder |
OAuth2Credentials.CredentialsChangedListener| Modifier and Type | Field and Description |
|---|---|
protected String |
quotaProjectId |
GOOGLE_DEFAULT_UNIVERSE| Modifier | Constructor and Description |
|---|---|
protected |
GoogleCredentials()
Default constructor.
|
|
GoogleCredentials(AccessToken accessToken)
Deprecated.
|
protected |
GoogleCredentials(AccessToken accessToken,
Duration refreshMargin,
Duration expirationMargin)
Deprecated.
|
protected |
GoogleCredentials(AccessToken accessToken,
String quotaProjectId)
Deprecated.
|
protected |
GoogleCredentials(GoogleCredentials.Builder builder)
Constructor that relies on a
GoogleCredentials.Builder to provide all the necessary field values for
initialization. |
| Modifier and Type | Method and Description |
|---|---|
static GoogleCredentials |
create(AccessToken accessToken)
Returns the credentials instance from the given access token.
|
static GoogleCredentials |
create(String universeDomain,
AccessToken accessToken)
Returns the credentials instance from the given access token and universe domain.
|
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.
|
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.
|
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.
|
GoogleCredentials |
createScoped(String... scopes)
If the credentials support scopes, creates a copy of the identity with the specified scopes;
otherwise, returns the same instance.
|
boolean |
createScopedRequired()
Indicates whether the credentials require scopes to be specified via a call to
createScoped(java.util.Collection<java.lang.String>) before use. |
GoogleCredentials |
createWithCustomRetryStrategy(boolean defaultRetriesEnabled)
If the credentials support automatic retries, creates a copy of the identity with the provided
retry strategy
|
GoogleCredentials |
createWithQuotaProject(String quotaProject)
Creates a credential with the provided quota project.
|
boolean |
equals(Object obj) |
static GoogleCredentials |
fromStream(InputStream credentialsStream)
Returns credentials defined by a JSON file stream.
|
static GoogleCredentials |
fromStream(InputStream credentialsStream,
HttpTransportFactory transportFactory)
Returns credentials defined by a JSON file stream.
|
protected Map<String,List<String>> |
getAdditionalHeaders()
Provide additional headers to return as request metadata.
|
static GoogleCredentials |
getApplicationDefault()
Returns the Application Default Credentials.
|
static GoogleCredentials |
getApplicationDefault(HttpTransportFactory transportFactory)
Returns the Application Default Credentials.
|
String |
getQuotaProjectId() |
String |
getUniverseDomain()
Gets the universe domain for the credential.
|
int |
hashCode() |
protected boolean |
isExplicitUniverseDomain()
Gets the flag indicating whether universeDomain was explicitly set by the developer.
|
static GoogleCredentials.Builder |
newBuilder() |
GoogleCredentials.Builder |
toBuilder() |
String |
toString() |
protected com.google.common.base.MoreObjects.ToStringHelper |
toStringHelper()
A helper for overriding the toString() method.
|
addChangeListener, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadata, getRequestMetadata, getRequestMetadataInternal, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshAccessToken, refreshIfExpired, removeChangeListenerblockingGetToCallback, getRequestMetadataprotected final String quotaProjectId
protected GoogleCredentials()
@Deprecated protected GoogleCredentials(AccessToken accessToken, String quotaProjectId)
Deprecated, please use the GoogleCredentials(Builder) constructor
whenever possible.
accessToken - initial or temporary access tokenquotaProjectId - a quotaProjectId, a project id to be used for billing purposes@Deprecated public GoogleCredentials(AccessToken accessToken)
accessToken - initial or temporary access tokenprotected GoogleCredentials(GoogleCredentials.Builder builder)
GoogleCredentials.Builder to provide all the necessary field values for
initialization.builder - an instance of a builder@Deprecated protected GoogleCredentials(AccessToken accessToken, Duration refreshMargin, Duration expirationMargin)
Deprecated, please use the GoogleCredentials(Builder) constructor
whenever possible.
accessToken - initial or temporary access tokenpublic static GoogleCredentials create(AccessToken accessToken)
accessToken - the access tokenpublic static GoogleCredentials create(String universeDomain, AccessToken accessToken)
universeDomain - the universe domainaccessToken - the access tokenpublic static GoogleCredentials getApplicationDefault() throws IOException
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:
GOOGLE_APPLICATION_CREDENTIALS environment
variable
gcloud auth application-default login for user account credentials.
gcloud auth application-default login --impersonate-service-account for
impersonated service account credentials.
IOException - if the credentials cannot be created in the current environment.public static GoogleCredentials getApplicationDefault(HttpTransportFactory transportFactory) throws IOException
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:
GOOGLE_APPLICATION_CREDENTIALS environment
variable
gcloud auth application-default
login command
transportFactory - HTTP transport factory, creates the transport used to get access
tokens.IOException - if the credentials cannot be created in the current environment.public static GoogleCredentials fromStream(InputStream credentialsStream) throws IOException
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.
credentialsStream - the stream with the credential definition.IOException - if the credential cannot be created from the stream.public static GoogleCredentials fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory) throws IOException
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.
credentialsStream - the stream with the credential definition.transportFactory - HTTP transport factory, creates the transport used to get access
tokens.IOException - if the credential cannot be created from the stream.public GoogleCredentials createWithQuotaProject(String quotaProject)
quotaProject - the quota project to set on the credentialpublic String getUniverseDomain() throws IOException
getUniverseDomain in class CredentialsIOExceptionprotected boolean isExplicitUniverseDomain()
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.
protected Map<String,List<String>> getAdditionalHeaders()
OAuth2CredentialsgetAdditionalHeaders in class OAuth2Credentialsprotected com.google.common.base.MoreObjects.ToStringHelper toStringHelper()
public String toString()
toString in class OAuth2Credentialspublic boolean equals(Object obj)
equals in class OAuth2Credentialspublic int hashCode()
hashCode in class OAuth2Credentialspublic static GoogleCredentials.Builder newBuilder()
public GoogleCredentials.Builder toBuilder()
toBuilder in class OAuth2Credentialspublic String getQuotaProjectId()
getQuotaProjectId in interface QuotaProjectIdProviderpublic boolean createScopedRequired()
createScoped(java.util.Collection<java.lang.String>) before use.public GoogleCredentials createScoped(Collection<String> scopes)
scopes - Collection of scopes to request.public GoogleCredentials createScoped(Collection<String> scopes, Collection<String> defaultScopes)
scopes - Collection of scopes to request.defaultScopes - Collection of default scopes to request.public GoogleCredentials createScoped(String... scopes)
scopes - Collection of scopes to request.public GoogleCredentials createWithCustomRetryStrategy(boolean defaultRetriesEnabled)
defaultRetriesEnabled - a flag enabling or disabling default retriespublic GoogleCredentials createDelegated(String user)
user - User to impersonate.Copyright © 2024 Google. All rights reserved.