public class ServiceAccountCredentials extends GoogleCredentials implements ServiceAccountSigner, IdTokenProvider, JwtProvider
By default uses a JSON Web Token (JWT) to fetch access tokens.
Modifier and Type | Class and Description |
---|---|
static class |
ServiceAccountCredentials.Builder |
OAuth2Credentials.CredentialsChangedListener
ServiceAccountSigner.SigningException
IdTokenProvider.Option
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() |
URI |
getTokenServerUri() |
int |
hashCode() |
IdToken |
idTokenWithAudience(String targetAudience,
List<IdTokenProvider.Option> options)
Returns a Google ID Token from the metadata server on ComputeEngine.
|
JwtCredentials |
jwtWithClaims(JwtClaims newClaims)
Returns a new JwtCredentials instance with modified claims.
|
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() |
create, createScoped, getApplicationDefault, getApplicationDefault
addChangeListener, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadata, getRequestMetadata, getRequestMetadataInternal, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshIfExpired, removeChangeListener
blockingGetToCallback, getRequestMetadata
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 empty collection,
which results in a credential that must have createScoped called before use.IOException
- if the credential cannot be created from the private key.public 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 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.IOException
- if the credential cannot be created from the private key.public 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 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.serviceAccountUser
- The email of the user account to impersonate, if delegating
domain-wide authority to the service account.IOException
- if the credential cannot be created from the private key.public 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 OAuth2Credentials
IOException
- from derived implementations@Beta public IdToken idTokenWithAudience(String targetAudience, List<IdTokenProvider.Option> options) throws IOException
idTokenWithAudience
in interface IdTokenProvider
targetAudience
- the aud: field the IdToken should include.options
- list of Credential specific options for for the token. Currently unused for
ServiceAccountCredentials.IOException
- if the attempt to get an IdToken failedpublic boolean createScopedRequired()
createScopedRequired
in class GoogleCredentials
public GoogleCredentials createScoped(Collection<String> newScopes)
Should be called before use for instances with empty scopes.
createScoped
in class GoogleCredentials
newScopes
- Collection of scopes to request.public GoogleCredentials createDelegated(String user)
GoogleCredentials
createDelegated
in class GoogleCredentials
user
- User to impersonate.public 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 final URI getTokenServerUri()
public String getAccount()
getAccount
in interface ServiceAccountSigner
public byte[] sign(byte[] toSign)
sign
in interface ServiceAccountSigner
public JwtCredentials jwtWithClaims(JwtClaims newClaims)
jwtWithClaims
in interface JwtProvider
newClaims
- new claims. Any unspecified claim fields will default to the the current
values.public int hashCode()
hashCode
in class OAuth2Credentials
public String toString()
toString
in class OAuth2Credentials
public boolean equals(Object obj)
equals
in class OAuth2Credentials
public static ServiceAccountCredentials.Builder newBuilder()
public ServiceAccountCredentials.Builder toBuilder()
toBuilder
in class GoogleCredentials
Copyright © 2019 Google. All rights reserved.