@@ -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,17 @@ public B setQuotaProjectId(String quotaProjectId) {
313316 return self ();
314317 }
315318
319+ /**
320+ * Sets the configuration determining whether self-signed JWT with scopes
321+ * are used for service account credentials.
322+ *
323+ * @return the builder
324+ */
325+ public B setUseJwtAccessWithScope (boolean useJwtAccessWithScope ) {
326+ this .useJwtAccessWithScope = useJwtAccessWithScope ;
327+ return self ();
328+ }
329+
316330 /**
317331 * Sets the {@link ApiTracerFactory}. It will be used to create an {@link ApiTracer} that is
318332 * annotated throughout the lifecycle of an RPC operation.
@@ -365,6 +379,7 @@ protected ServiceOptions(
365379 builder .quotaProjectId != null
366380 ? builder .quotaProjectId
367381 : getValueFromCredentialsFile (getCredentialsPath (), "quota_project_id" );
382+ useJwtAccessWithScope = builder .useJwtAccessWithScope ;
368383 apiTracerFactory = builder .apiTracerFactory ;
369384 }
370385
@@ -650,17 +665,13 @@ public Credentials getScopedCredentials() {
650665 && ((GoogleCredentials ) credentials ).createScopedRequired ()) {
651666 credentialsToReturn = ((GoogleCredentials ) credentials ).createScoped (getScopes ());
652667 }
653- if (useSelfSignedJwt () && credentialsToReturn instanceof ServiceAccountCredentials ) {
668+ if (getUseJwtAccessWithScope () && credentialsToReturn instanceof ServiceAccountCredentials ) {
654669 credentialsToReturn =
655670 ((ServiceAccountCredentials ) credentialsToReturn ).createWithUseJwtAccessWithScope (true );
656671 }
657672 return credentialsToReturn ;
658673 }
659674
660- protected boolean useSelfSignedJwt () {
661- return true ;
662- }
663-
664675 /** Returns configuration parameters for request retries. */
665676 public RetrySettings getRetrySettings () {
666677 return retrySettings ;
@@ -831,6 +842,14 @@ public String getQuotaProjectId() {
831842 return quotaProjectId ;
832843 }
833844
845+ /**
846+ * Returns true when self-signed JWT with scopes are used for service account
847+ * credentials.
848+ */
849+ public boolean getUseJwtAccessWithScope () {
850+ return useJwtAccessWithScope ;
851+ }
852+
834853 /**
835854 * Returns the resolved host for the Service to connect to Google Cloud
836855 *
0 commit comments