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 |
Modifier | Constructor and Description |
---|---|
protected |
GoogleCredentials()
Default constructor.
|
|
GoogleCredentials(AccessToken accessToken)
Constructor with explicit access token.
|
protected |
GoogleCredentials(AccessToken accessToken,
Duration refreshMargin,
Duration expirationMargin)
Constructor with explicit access token and refresh times
|
protected |
GoogleCredentials(AccessToken accessToken,
String quotaProjectId) |
protected |
GoogleCredentials(GoogleCredentials.Builder builder) |
Modifier and Type | Method and Description |
---|---|
static GoogleCredentials |
create(AccessToken accessToken)
Returns the credentials instance from the given access token.
|
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;
otherwise, returns 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.
|
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() |
static GoogleCredentials.Builder |
newBuilder() |
GoogleCredentials.Builder |
toBuilder() |
addChangeListener, equals, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadata, getRequestMetadata, getRequestMetadataInternal, hashCode, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshAccessToken, refreshIfExpired, removeChangeListener, toString
blockingGetToCallback, getRequestMetadata
protected final String quotaProjectId
protected GoogleCredentials()
protected GoogleCredentials(AccessToken accessToken, String quotaProjectId)
public GoogleCredentials(AccessToken accessToken)
accessToken
- initial or temporary access tokenprotected GoogleCredentials(GoogleCredentials.Builder builder)
protected GoogleCredentials(AccessToken accessToken, Duration refreshMargin, Duration expirationMargin)
accessToken
- initial or temporary access tokenpublic static GoogleCredentials create(AccessToken accessToken)
accessToken
- 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 credentialprotected Map<String,List<String>> getAdditionalHeaders()
OAuth2Credentials
getAdditionalHeaders
in class OAuth2Credentials
public static GoogleCredentials.Builder newBuilder()
public GoogleCredentials.Builder toBuilder()
toBuilder
in class OAuth2Credentials
public String getQuotaProjectId()
getQuotaProjectId
in interface QuotaProjectIdProvider
public 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 © 2023 Google. All rights reserved.