public class CredentialFactory extends Object
Credential from various sources.| Modifier and Type | Class and Description |
|---|---|
static class |
CredentialFactory.ComputeCredentialWithRetry
A subclass of ComputeCredential that properly sets request initializers.
|
static class |
CredentialFactory.CredentialHttpRetryInitializer
Simple HttpRequestInitializer that retries requests that result in 5XX response codes and
IO Exceptions with an exponential backoff.
|
static class |
CredentialFactory.GoogleCredentialWithRetry
A subclass of
GoogleCredential that properly wires specified
HttpRequestInitializer through the @{link Credential#executeRefreshToken} override. |
| Modifier and Type | Field and Description |
|---|---|
static List<String> |
DATASTORE_SCOPES |
static List<String> |
GCS_SCOPES |
| Constructor and Description |
|---|
CredentialFactory() |
| Modifier and Type | Method and Description |
|---|---|
com.google.api.client.auth.oauth2.Credential |
getCredentialFromFileCredentialStoreForInstalledApp(String clientId,
String clientSecret,
String filePath,
List<String> scopes)
Initialized OAuth2 credential for the "installed application" flow; where the credential
typically represents an actual end user (instead of a service account), and is stored
as a refresh token in a local FileCredentialStore.
|
com.google.api.client.auth.oauth2.Credential |
getCredentialFromJsonKeyFile(String serviceAccountJsonKeyFile,
List<String> scopes)
Get credentials listed in a JSON file.
|
com.google.api.client.auth.oauth2.Credential |
getCredentialFromMetadataServiceAccount()
Initializes OAuth2 credential using preconfigured ServiceAccount settings on the local
GCE VM.
|
com.google.api.client.auth.oauth2.Credential |
getCredentialFromPrivateKeyServiceAccount(String serviceAccountEmail,
String privateKeyFile,
List<String> scopes)
Initializes OAuth2 credential from a private keyfile, as described in
OAuth2 Service Accounts.
|
com.google.api.client.auth.oauth2.Credential |
getDatastoreCredential(String clientId,
String clientSecret)
Initializes OAuth2 credential and obtains authorization to access Datastore.
|
com.google.api.client.auth.oauth2.Credential |
getStorageCredential(String clientId,
String clientSecret)
Initializes OAuth2 credential and obtains authorization to access GCS.
|
public com.google.api.client.auth.oauth2.Credential getCredentialFromMetadataServiceAccount()
throws IOException,
GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic com.google.api.client.auth.oauth2.Credential getCredentialFromPrivateKeyServiceAccount(String serviceAccountEmail, String privateKeyFile, List<String> scopes) throws IOException, GeneralSecurityException
serviceAccountEmail - Email address of the service account associated with the keyfile.privateKeyFile - Full local path to private keyfile.scopes - List of well-formed desired scopes to use with the credential.IOExceptionGeneralSecurityExceptionpublic com.google.api.client.auth.oauth2.Credential getCredentialFromJsonKeyFile(String serviceAccountJsonKeyFile, List<String> scopes) throws IOException, GeneralSecurityException
serviceAccountJsonKeyFile - A file path pointing to a JSON file containing credentials.scopes - The OAuth scopes that the credential should be valid for.IOExceptionGeneralSecurityExceptionpublic com.google.api.client.auth.oauth2.Credential getCredentialFromFileCredentialStoreForInstalledApp(String clientId, String clientSecret, String filePath, List<String> scopes) throws IOException, GeneralSecurityException
clientId - OAuth2 client ID identifying the 'installed app'clientSecret - OAuth2 client secretfilePath - full path to a ".json" file for storing the credentialscopes - list of well-formed scopes desired in the credentialfilePath.IOException - on IO errorGeneralSecurityExceptionpublic com.google.api.client.auth.oauth2.Credential getStorageCredential(String clientId, String clientSecret) throws IOException, GeneralSecurityException
clientId - OAuth2 client IDclientSecret - OAuth2 client secretIOException - on IO errorGeneralSecurityExceptionpublic com.google.api.client.auth.oauth2.Credential getDatastoreCredential(String clientId, String clientSecret) throws IOException, GeneralSecurityException
clientId - OAuth2 client IDclientSecret - OAuth2 client secretIOException - on IO errorGeneralSecurityExceptionCopyright © 2016. All rights reserved.