Package com.google.auth.oauth2
Class ServiceAccountJwtAccessCredentials
java.lang.Object
com.google.auth.Credentials
com.google.auth.oauth2.ServiceAccountJwtAccessCredentials
- All Implemented Interfaces:
JwtProvider,QuotaProjectIdProvider,ServiceAccountSigner,Serializable
public class ServiceAccountJwtAccessCredentials
extends Credentials
implements JwtProvider, ServiceAccountSigner, QuotaProjectIdProvider
Service Account credentials for calling Google APIs using a JWT directly for access.
Uses a JSON Web Token (JWT) directly in the request metadata to provide authorization.
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface com.google.auth.ServiceAccountSigner
ServiceAccountSigner.SigningException -
Field Summary
Fields inherited from class com.google.auth.Credentials
GOOGLE_DEFAULT_UNIVERSE -
Method Summary
Modifier and TypeMethodDescriptionbooleanFactory using PKCS#8 for the private key.fromPkcs8(String clientId, String clientEmail, String privateKeyPkcs8, String privateKeyId, URI defaultAudience) Factory using PKCS#8 for the private key.fromStream(InputStream credentialsStream) Returns credentials defined by a Service Account key file in JSON format from the Google Developers Console.fromStream(InputStream credentialsStream, URI defaultAudience) Returns credentials defined by a Service Account key file in JSON format from the Google Developers Console.final Stringfinal Stringfinal PrivateKeyfinal StringgetRequestMetadata(URI uri) Provide the request metadata by putting an access JWT directly in the metadata.voidgetRequestMetadata(URI uri, Executor executor, RequestMetadataCallback callback) final StringReturns the universe domain (example, googleapis.com) for the credentials instance.inthashCode()booleanbooleanjwtWithClaims(JwtClaims newClaims) Returns a new JwtCredentials instance with modified claims.voidrefresh()Discard any cached databyte[]sign(byte[] toSign) toString()Methods inherited from class com.google.auth.Credentials
blockingGetToCallback, getMetricsCredentialType, getRequestMetadata
-
Method Details
-
fromPkcs8
public static ServiceAccountJwtAccessCredentials fromPkcs8(String clientId, String clientEmail, String privateKeyPkcs8, String privateKeyId) throws IOException Factory using PKCS#8 for the private key.- Parameters:
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.- Returns:
- New ServiceAccountJwtAcceessCredentials created from a private key.
- Throws:
IOException- if the credential cannot be created from the private key.
-
fromPkcs8
public static ServiceAccountJwtAccessCredentials fromPkcs8(String clientId, String clientEmail, String privateKeyPkcs8, String privateKeyId, URI defaultAudience) throws IOException Factory using PKCS#8 for the private key.- Parameters:
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.defaultAudience- Audience to use if not provided by transport. May be null.- Returns:
- New ServiceAccountJwtAcceessCredentials created from a private key.
- Throws:
IOException- if the credential cannot be created from the private key.
-
fromStream
public static ServiceAccountJwtAccessCredentials fromStream(InputStream credentialsStream) throws IOException Returns credentials defined by a Service Account key file in JSON format from the Google Developers Console.- Parameters:
credentialsStream- the stream with the credential definition.- Returns:
- the credential defined by the credentialsStream.
- Throws:
IOException- if the credential cannot be created from the stream.
-
fromStream
public static ServiceAccountJwtAccessCredentials fromStream(InputStream credentialsStream, URI defaultAudience) throws IOException Returns credentials defined by a Service Account key file in JSON format from the Google Developers Console.- Parameters:
credentialsStream- the stream with the credential definition.defaultAudience- Audience to use if not provided by transport. May be null.- Returns:
- the credential defined by the credentialsStream.
- Throws:
IOException- if the credential cannot be created from the stream.
-
jwtWithClaims
Returns a new JwtCredentials instance with modified claims.- Specified by:
jwtWithClaimsin interfaceJwtProvider- Parameters:
newClaims- new claims. Any unspecified claim fields will default to the current values.- Returns:
- new credentials
-
getAuthenticationType
- Specified by:
getAuthenticationTypein classCredentials
-
hasRequestMetadata
public boolean hasRequestMetadata()- Specified by:
hasRequestMetadatain classCredentials
-
hasRequestMetadataOnly
public boolean hasRequestMetadataOnly()- Specified by:
hasRequestMetadataOnlyin classCredentials
-
getRequestMetadata
- Overrides:
getRequestMetadatain classCredentials
-
getRequestMetadata
Provide the request metadata by putting an access JWT directly in the metadata.- Specified by:
getRequestMetadatain classCredentials- Throws:
IOException
-
refresh
public void refresh()Discard any cached data- Specified by:
refreshin classCredentials
-
getClientId
-
getClientEmail
-
getPrivateKey
-
getPrivateKeyId
-
getUniverseDomain
Returns the universe domain (example, googleapis.com) for the credentials instance.- Overrides:
getUniverseDomainin classCredentials
-
getAccount
- Specified by:
getAccountin interfaceServiceAccountSigner
-
sign
public byte[] sign(byte[] toSign) - Specified by:
signin interfaceServiceAccountSigner
-
hashCode
public int hashCode() -
toString
-
equals
-
newBuilder
-
toBuilder
-
getQuotaProjectId
- Specified by:
getQuotaProjectIdin interfaceQuotaProjectIdProvider- Returns:
- the quota project ID used for quota and billing purposes
-