@@ -106,6 +106,7 @@ public abstract class ServiceOptions<
106106 private final TransportOptions transportOptions ;
107107 private final HeaderProvider headerProvider ;
108108 private final String quotaProjectId ;
109+ private final boolean useJwtAccessWithScope ;
109110
110111 private transient ServiceRpcFactory <OptionsT > serviceRpcFactory ;
111112 private transient ServiceFactory <ServiceT , OptionsT > serviceFactory ;
@@ -140,6 +141,7 @@ public abstract static class Builder<
140141 private HeaderProvider headerProvider ;
141142 private String clientLibToken = ServiceOptions .getGoogApiClientLibName ();
142143 private String quotaProjectId ;
144+ private boolean useJwtAccessWithScope = true ;
143145
144146 private ApiTracerFactory apiTracerFactory ;
145147
@@ -159,6 +161,7 @@ protected Builder(ServiceOptions<ServiceT, OptionsT> options) {
159161 transportOptions = options .transportOptions ;
160162 clientLibToken = options .clientLibToken ;
161163 quotaProjectId = options .quotaProjectId ;
164+ useJwtAccessWithScope = options .useJwtAccessWithScope ;
162165 apiTracerFactory = options .apiTracerFactory ;
163166 }
164167
@@ -313,6 +316,18 @@ public B setQuotaProjectId(String quotaProjectId) {
313316 return self ();
314317 }
315318
319+ /**
320+ * Sets the configuration determining whether self-signed JWT with scopes are used for service
321+ * account credentials.
322+ *
323+ * @param useJwtAccessWithScope whether to use self-signed JWT with scopes
324+ * @return the builder
325+ */
326+ public B setUseJwtAccessWithScope (final boolean useJwtAccessWithScope ) {
327+ this .useJwtAccessWithScope = useJwtAccessWithScope ;
328+ return self ();
329+ }
330+
316331 /**
317332 * Sets the {@link ApiTracerFactory}. It will be used to create an {@link ApiTracer} that is
318333 * annotated throughout the lifecycle of an RPC operation.
@@ -365,6 +380,7 @@ protected ServiceOptions(
365380 builder .quotaProjectId != null
366381 ? builder .quotaProjectId
367382 : getValueFromCredentialsFile (getCredentialsPath (), "quota_project_id" );
383+ useJwtAccessWithScope = builder .useJwtAccessWithScope ;
368384 apiTracerFactory = builder .apiTracerFactory ;
369385 }
370386
@@ -650,17 +666,13 @@ public Credentials getScopedCredentials() {
650666 && ((GoogleCredentials ) credentials ).createScopedRequired ()) {
651667 credentialsToReturn = ((GoogleCredentials ) credentials ).createScoped (getScopes ());
652668 }
653- if (useSelfSignedJwt () && credentialsToReturn instanceof ServiceAccountCredentials ) {
669+ if (getUseJwtAccessWithScope () && credentialsToReturn instanceof ServiceAccountCredentials ) {
654670 credentialsToReturn =
655671 ((ServiceAccountCredentials ) credentialsToReturn ).createWithUseJwtAccessWithScope (true );
656672 }
657673 return credentialsToReturn ;
658674 }
659675
660- protected boolean useSelfSignedJwt () {
661- return true ;
662- }
663-
664676 /** Returns configuration parameters for request retries. */
665677 public RetrySettings getRetrySettings () {
666678 return retrySettings ;
@@ -831,6 +843,15 @@ public String getQuotaProjectId() {
831843 return quotaProjectId ;
832844 }
833845
846+ /**
847+ * Returns true when self-signed JWT with scopes are used for service account credentials.
848+ *
849+ * @return true when self-signed JWT with scopes are used
850+ */
851+ public boolean getUseJwtAccessWithScope () {
852+ return useJwtAccessWithScope ;
853+ }
854+
834855 /**
835856 * Returns the resolved host for the Service to connect to Google Cloud
836857 *
0 commit comments