public class ServiceAccountJwtAccessCredentials extends Credentials implements JwtProvider, ServiceAccountSigner, QuotaProjectIdProvider
Uses a JSON Web Token (JWT) directly in the request metadata to provide authorization.
Modifier and Type | Class and Description |
---|---|
static class |
ServiceAccountJwtAccessCredentials.Builder |
ServiceAccountSigner.SigningException
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
static ServiceAccountJwtAccessCredentials |
fromPkcs8(String clientId,
String clientEmail,
String privateKeyPkcs8,
String privateKeyId)
Factory using PKCS#8 for the private key.
|
static ServiceAccountJwtAccessCredentials |
fromPkcs8(String clientId,
String clientEmail,
String privateKeyPkcs8,
String privateKeyId,
URI defaultAudience)
Factory using PKCS#8 for the private key.
|
static ServiceAccountJwtAccessCredentials |
fromStream(InputStream credentialsStream)
Returns credentials defined by a Service Account key file in JSON format from the Google
Developers Console.
|
static ServiceAccountJwtAccessCredentials |
fromStream(InputStream credentialsStream,
URI defaultAudience)
Returns credentials defined by a Service Account key file in JSON format from the Google
Developers Console.
|
String |
getAccount()
Returns the service account associated with the signer.
|
String |
getAuthenticationType()
A constant string name describing the authentication technology.
|
String |
getClientEmail() |
String |
getClientId() |
PrivateKey |
getPrivateKey() |
String |
getPrivateKeyId() |
String |
getQuotaProjectId() |
Map<String,List<String>> |
getRequestMetadata(URI uri)
Provide the request metadata by putting an access JWT directly in the metadata.
|
void |
getRequestMetadata(URI uri,
Executor executor,
RequestMetadataCallback callback)
Get the current request metadata without blocking.
|
int |
hashCode() |
boolean |
hasRequestMetadata()
Whether the credentials have metadata entries that should be added to each request.
|
boolean |
hasRequestMetadataOnly()
Indicates whether or not the Auth mechanism works purely by including request metadata.
|
JwtCredentials |
jwtWithClaims(JwtClaims newClaims)
Returns a new JwtCredentials instance with modified claims.
|
static ServiceAccountJwtAccessCredentials.Builder |
newBuilder() |
void |
refresh()
Discard any cached data
|
byte[] |
sign(byte[] toSign)
Signs the provided bytes using the private key associated with the service account.
|
ServiceAccountJwtAccessCredentials.Builder |
toBuilder() |
String |
toString() |
blockingGetToCallback, getRequestMetadata
public static ServiceAccountJwtAccessCredentials fromPkcs8(String clientId, String clientEmail, String privateKeyPkcs8, String privateKeyId) 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.IOException
- if the credential cannot be created from the private key.public static ServiceAccountJwtAccessCredentials fromPkcs8(String clientId, String clientEmail, String privateKeyPkcs8, String privateKeyId, URI defaultAudience) 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.defaultAudience
- Audience to use if not provided by transport. May be null.IOException
- if the credential cannot be created from the private key.public static ServiceAccountJwtAccessCredentials fromStream(InputStream credentialsStream) throws IOException
credentialsStream
- the stream with the credential definition.IOException
- if the credential cannot be created from the stream.public static ServiceAccountJwtAccessCredentials fromStream(InputStream credentialsStream, URI defaultAudience) throws IOException
credentialsStream
- the stream with the credential definition.defaultAudience
- Audience to use if not provided by transport. May be null.IOException
- if the credential cannot be created from the stream.public JwtCredentials jwtWithClaims(JwtClaims newClaims)
jwtWithClaims
in interface JwtProvider
newClaims
- new claims. Any unspecified claim fields will default to the the current
values.public String getAuthenticationType()
Credentials
E.g. “OAuth2”, “SSL”. For use by the transport layer to determine whether it supports the
type of authentication in the case where Credentials.hasRequestMetadataOnly()
is false.
Also serves as a debugging helper.
getAuthenticationType
in class Credentials
public boolean hasRequestMetadata()
Credentials
This should be called by the transport layer to see if Credentials.getRequestMetadata()
should be used for each request.
hasRequestMetadata
in class Credentials
Credentials.getRequestMetadata()
public boolean hasRequestMetadataOnly()
Credentials
This is meant for the transport layer. If this is true a transport does not need to take actions other than including the request metadata. If this is false, a transport must specifically know about the authentication technology to support it, and should fail to accept the credentials otherwise.
hasRequestMetadataOnly
in class Credentials
public void getRequestMetadata(URI uri, Executor executor, RequestMetadataCallback callback)
Credentials
This should be called by the transport layer on each request, and the data should be populated in headers or other context. The implementation can either call the callback inline or asynchronously. Either way it should never block in this method. The executor is provided for tasks that may block.
The default implementation will just call Credentials.getRequestMetadata(URI)
then the callback
from the given executor.
The convention for handling binary data is for the key in the returned map to end with
"-bin"
and for the corresponding values to be base64 encoded.
getRequestMetadata
in class Credentials
uri
- URI of the entry point for the request.executor
- Executor to perform the request.callback
- Callback to execute when the request is finished.public Map<String,List<String>> getRequestMetadata(URI uri) throws IOException
getRequestMetadata
in class Credentials
uri
- URI of the entry point for the request.IOException
- if there was an error getting up-to-date access. The exception should
implement Retryable
and isRetryable()
will return true if the operation may
be retried.public void refresh()
refresh
in class Credentials
public final String getClientId()
public final String getClientEmail()
public final PrivateKey getPrivateKey()
public final String getPrivateKeyId()
public String getAccount()
ServiceAccountSigner
getAccount
in interface ServiceAccountSigner
public byte[] sign(byte[] toSign)
ServiceAccountSigner
sign
in interface ServiceAccountSigner
toSign
- bytes to signpublic static ServiceAccountJwtAccessCredentials.Builder newBuilder()
public ServiceAccountJwtAccessCredentials.Builder toBuilder()
public String getQuotaProjectId()
getQuotaProjectId
in interface QuotaProjectIdProvider
Copyright © 2023 Google. All rights reserved.