public class GoogleCredentials extends OAuth2Credentials
Base type for credentials for authorizing calls to Google APIs using OAuth2.
Constructors
GoogleCredentials()
protected GoogleCredentials()
Default constructor.
GoogleCredentials(AccessToken accessToken)
public GoogleCredentials(AccessToken accessToken)
Constructor with explicit access token.
Name | Description |
accessToken | AccessToken initial or temporary access token |
GoogleCredentials(AccessToken accessToken, Duration refreshMargin, Duration expirationMargin)
protected GoogleCredentials(AccessToken accessToken, Duration refreshMargin, Duration expirationMargin)
Constructor with explicit access token and refresh times
Name | Description |
accessToken | AccessToken initial or temporary access token |
refreshMargin | Duration |
expirationMargin | Duration |
Methods
create(AccessToken accessToken)
public static GoogleCredentials create(AccessToken accessToken)
Returns the credentials instance from the given access token.
Name | Description |
accessToken | AccessToken the access token |
Type | Description |
GoogleCredentials | the credentials instance |
createDelegated(String user)
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.
Name | Description |
user | String User to impersonate. |
Type | Description |
GoogleCredentials | GoogleCredentials with a delegated user. |
createScoped(String[] scopes)
public GoogleCredentials createScoped(String[] scopes)
If the credentials support scopes, creates a copy of the the identity with the specified scopes; otherwise, returns the same instance.
Name | Description |
scopes | String[] Collection of scopes to request. |
Type | Description |
GoogleCredentials | GoogleCredentials with requested scopes. |
createScoped(Collection<String> scopes)
public GoogleCredentials createScoped(Collection<String> scopes)
If the credentials support scopes, creates a copy of the the identity with the specified scopes; otherwise, returns the same instance.
Name | Description |
scopes | Collection<String> Collection of scopes to request. |
Type | Description |
GoogleCredentials | GoogleCredentials with requested scopes. |
createScoped(Collection<String> scopes, Collection<String> defaultScopes)
public GoogleCredentials createScoped(Collection<String> scopes, Collection<String> defaultScopes)
If the credentials support scopes, creates a copy of the the identity with the specified scopes and default scopes; otherwise, returns the same instance. This is mainly used by client libraries.
Name | Description |
scopes | Collection<String> Collection of scopes to request. |
defaultScopes | Collection<String> Collection of default scopes to request. |
Type | Description |
GoogleCredentials | GoogleCredentials with requested scopes. |
createScopedRequired()
public boolean createScopedRequired()
Indicates whether the credentials require scopes to be specified via a call to GoogleCredentials#createScoped before use.
Type | Description |
boolean | Whether the credentials require scopes to be specified. |
fromStream(InputStream credentialsStream)
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.
Name | Description |
credentialsStream | InputStream the stream with the credential definition. |
Type | Description |
GoogleCredentials | the credential defined by the credentialsStream. |
Type | Description |
IOException | if the credential cannot be created from the stream. |
fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory)
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.
Name | Description |
credentialsStream | InputStream the stream with the credential definition. |
transportFactory | HttpTransportFactory HTTP transport factory, creates the transport used to get access tokens. |
Type | Description |
GoogleCredentials | the credential defined by the credentialsStream. |
Type | Description |
IOException | 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.
Type | Description |
GoogleCredentials | the credentials instance. |
Type | Description |
IOException | if the credentials cannot be created in the current environment. |
getApplicationDefault(HttpTransportFactory transportFactory)
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
Name | Description |
transportFactory | HttpTransportFactory HTTP transport factory, creates the transport used to get access tokens. |
Type | Description |
GoogleCredentials | the credentials instance. |
Type | Description |
IOException | if the credentials cannot be created in the current environment. |
newBuilder()
public static GoogleCredentials.Builder newBuilder()
Type | Description |
GoogleCredentials.Builder |
toBuilder()
public GoogleCredentials.Builder toBuilder()
Type | Description |
GoogleCredentials.Builder |