public class ServiceAccountCredentials extends GoogleCredentials implements ServiceAccountSigner
By default uses a JSON Web Token (JWT) to fetch access tokens.
| Modifier and Type | Class and Description |
|---|---|
static class |
ServiceAccountCredentials.Builder |
OAuth2Credentials.CredentialsChangedListenerServiceAccountSigner.SigningException| Constructor and Description |
|---|
ServiceAccountCredentials(String clientId,
String clientEmail,
PrivateKey privateKey,
String privateKeyId,
Collection<String> scopes)
Deprecated.
|
ServiceAccountCredentials(String clientId,
String clientEmail,
PrivateKey privateKey,
String privateKeyId,
Collection<String> scopes,
HttpTransportFactory transportFactory,
URI tokenServerUri)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
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> newScopes)
Clones the service account with the specified scopes.
|
boolean |
createScopedRequired()
Returns whether the scopes are empty, meaning createScoped must be called before use.
|
boolean |
equals(Object obj) |
static ServiceAccountCredentials |
fromPkcs8(String clientId,
String clientEmail,
String privateKeyPkcs8,
String privateKeyId,
Collection<String> scopes)
Factory with minimum identifying information using PKCS#8 for the private key.
|
static ServiceAccountCredentials |
fromPkcs8(String clientId,
String clientEmail,
String privateKeyPkcs8,
String privateKeyId,
Collection<String> scopes,
HttpTransportFactory transportFactory,
URI tokenServerUri)
Factory with minimum identifying information and custom transport using PKCS#8 for the
private key.
|
static ServiceAccountCredentials |
fromPkcs8(String clientId,
String clientEmail,
String privateKeyPkcs8,
String privateKeyId,
Collection<String> scopes,
HttpTransportFactory transportFactory,
URI tokenServerUri,
String serviceAccountUser)
Factory with minimum identifying information and custom transport using PKCS#8 for the
private key.
|
static ServiceAccountCredentials |
fromStream(InputStream credentialsStream)
Returns credentials defined by a Service Account key file in JSON format from the Google
Developers Console.
|
static ServiceAccountCredentials |
fromStream(InputStream credentialsStream,
HttpTransportFactory transportFactory)
Returns credentials defined by a Service Account key file in JSON format from the Google
Developers Console.
|
String |
getAccount() |
String |
getClientEmail() |
String |
getClientId() |
PrivateKey |
getPrivateKey() |
String |
getPrivateKeyId() |
String |
getProjectId() |
Collection<String> |
getScopes() |
String |
getServiceAccountUser() |
int |
hashCode() |
static ServiceAccountCredentials.Builder |
newBuilder() |
AccessToken |
refreshAccessToken()
Refreshes the OAuth2 access token by getting a new access token using a JSON Web Token (JWT).
|
byte[] |
sign(byte[] toSign) |
ServiceAccountCredentials.Builder |
toBuilder() |
String |
toString() |
getApplicationDefault, getApplicationDefault, ofaddChangeListener, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadata, getRequestMetadata, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, toStringHelperblockingGetToCallback, getRequestMetadata@Deprecated public ServiceAccountCredentials(String clientId, String clientEmail, PrivateKey privateKey, String privateKeyId, Collection<String> scopes)
clientId - Client ID of the service account from the console. May be null.clientEmail - Client email address of the service account from the console.privateKey - RSA private key object for the service account.privateKeyId - Private key identifier for the service account. May be null.scopes - Scope strings for the APIs to be called. May be null or an empty collection,
which results in a credential that must have createScoped called before use.@Deprecated public ServiceAccountCredentials(String clientId, String clientEmail, PrivateKey privateKey, String privateKeyId, Collection<String> scopes, HttpTransportFactory transportFactory, URI tokenServerUri)
clientId - Client ID of the service account from the console. May be null.clientEmail - Client email address of the service account from the console.privateKey - RSA private key object for the service account.privateKeyId - Private key identifier for the service account. May be null.scopes - Scope strings for the APIs to be called. May be null or an empty collection,
which results in a credential that must have createScoped called before use.transportFactory - HTTP transport factory, creates the transport used to get access
tokens.tokenServerUri - URI of the end point that provides tokens.public static ServiceAccountCredentials fromPkcs8(String clientId, String clientEmail, String privateKeyPkcs8, String privateKeyId, Collection<String> scopes) throws IOException
clientId - Client ID of the service account from the console. May be null.clientEmail - Client email address of the service account from the console.privateKeyPkcs8 - RSA private key object for the service account in PKCS#8 format.privateKeyId - Private key identifier for the service account. May be null.scopes - Scope strings for the APIs to be called. May be null or an emptt collection,
which results in a credential that must have createScoped called before use.IOExceptionpublic static ServiceAccountCredentials fromPkcs8(String clientId, String clientEmail, String privateKeyPkcs8, String privateKeyId, Collection<String> scopes, HttpTransportFactory transportFactory, URI tokenServerUri) throws IOException
clientId - Client ID of the service account from the console. May be null.clientEmail - Client email address of the service account from the console.privateKeyPkcs8 - RSA private key object for the service account in PKCS#8 format.privateKeyId - Private key identifier for the service account. May be null.scopes - Scope strings for the APIs to be called. May be null or an emptt collection,
which results in a credential that must have createScoped called before use.transportFactory - HTTP transport factory, creates the transport used to get access
tokens.tokenServerUri - URI of the end point that provides tokens.IOExceptionpublic static ServiceAccountCredentials fromPkcs8(String clientId, String clientEmail, String privateKeyPkcs8, String privateKeyId, Collection<String> scopes, HttpTransportFactory transportFactory, URI tokenServerUri, String serviceAccountUser) throws IOException
clientId - Client ID of the service account from the console. May be null.clientEmail - Client email address of the service account from the console.privateKeyPkcs8 - RSA private key object for the service account in PKCS#8 format.privateKeyId - Private key identifier for the service account. May be null.scopes - Scope strings for the APIs to be called. May be null or an emptt collection,
which results in a credential that must have createScoped called before use.transportFactory - HTTP transport factory, creates the transport used to get access
tokens.tokenServerUri - URI of the end point that provides tokens.serviceAccountUser - The email of the user account to impersonate, if delegating
domain-wide authority to the service account.IOExceptionpublic static ServiceAccountCredentials fromStream(InputStream credentialsStream) throws IOException
credentialsStream - the stream with the credential definition.IOException - if the credential cannot be created from the stream.public static ServiceAccountCredentials fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory) throws IOException
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 AccessToken refreshAccessToken() throws IOException
refreshAccessToken in class OAuth2CredentialsIOException - from derived implementationspublic boolean createScopedRequired()
createScopedRequired in class GoogleCredentialspublic GoogleCredentials createScoped(Collection<String> newScopes)
Should be called before use for instances with empty scopes.
createScoped in class GoogleCredentialspublic GoogleCredentials createDelegated(String user)
GoogleCredentialscreateDelegated in class GoogleCredentialspublic final String getClientId()
public final String getClientEmail()
public final PrivateKey getPrivateKey()
public final String getPrivateKeyId()
public final Collection<String> getScopes()
public final String getServiceAccountUser()
public final String getProjectId()
public String getAccount()
getAccount in interface ServiceAccountSignerpublic byte[] sign(byte[] toSign)
sign in interface ServiceAccountSignerpublic int hashCode()
hashCode in class OAuth2Credentialspublic String toString()
toString in class OAuth2Credentialspublic boolean equals(Object obj)
equals in class OAuth2Credentialspublic static ServiceAccountCredentials.Builder newBuilder()
public ServiceAccountCredentials.Builder toBuilder()
toBuilder in class GoogleCredentialsCopyright © 2017 Google. All rights reserved.