1111import com .auth0 .jwk .JwkException ;
1212import com .auth0 .jwk .JwkProvider ;
1313import com .auth0 .jwk .UrlJwkProvider ;
14+ import com .auth0 .net .client .Auth0HttpClient ;
1415import com .auth0 .net .client .DefaultHttpClient ;
1516import com .auth0 .utils .tokens .IdTokenVerifier ;
1617import com .auth0 .utils .tokens .SignatureVerifier ;
@@ -50,6 +51,7 @@ class RequestProcessor {
5051 private final String clientId ;
5152 private final String clientSecret ;
5253 private final JwkProvider jwkProvider ;
54+ private Auth0HttpClient httpClient ;
5355
5456 private final Integer clockSkew ;
5557 private final Integer authenticationMaxAge ;
@@ -71,6 +73,7 @@ static class Builder {
7173 private final String clientSecret ;
7274
7375 private JwkProvider jwkProvider ;
76+ private Auth0HttpClient httpClient ;
7477 private boolean useLegacySameSiteCookie = true ;
7578 private Integer clockSkew ;
7679 private Integer authenticationMaxAge ;
@@ -93,6 +96,11 @@ Builder withJwkProvider(JwkProvider jwkProvider) {
9396 return this ;
9497 }
9598
99+ Builder withHttpClient (Auth0HttpClient httpClient ) {
100+ this .httpClient = httpClient ;
101+ return this ;
102+ }
103+
96104 public Builder withClockSkew (Integer clockSkew ) {
97105 this .clockSkew = clockSkew ;
98106 return this ;
@@ -125,20 +133,21 @@ Builder withInvitation(String invitation) {
125133
126134 RequestProcessor build () {
127135 return new RequestProcessor (domainProvider , responseType , clientId , clientSecret ,
128- jwkProvider , useLegacySameSiteCookie , clockSkew , authenticationMaxAge ,
136+ jwkProvider , httpClient , useLegacySameSiteCookie , clockSkew , authenticationMaxAge ,
129137 organization , invitation , cookiePath );
130138 }
131139 }
132140
133141 private RequestProcessor (DomainProvider domainProvider , String responseType , String clientId ,
134- String clientSecret , JwkProvider jwkProvider ,
142+ String clientSecret , JwkProvider jwkProvider , Auth0HttpClient httpClient ,
135143 boolean useLegacySameSiteCookie , Integer clockSkew , Integer authenticationMaxAge ,
136144 String organization , String invitation , String cookiePath ) {
137145 this .domainProvider = domainProvider ;
138146 this .responseType = responseType ;
139147 this .clientId = clientId ;
140148 this .clientSecret = clientSecret ;
141149 this .jwkProvider = jwkProvider ;
150+ this .httpClient = httpClient ;
142151 this .useLegacySameSiteCookie = useLegacySameSiteCookie ;
143152 this .clockSkew = clockSkew ;
144153 this .authenticationMaxAge = authenticationMaxAge ;
@@ -156,18 +165,23 @@ void doNotSendTelemetry() {
156165 }
157166
158167 AuthAPI createClientForDomain (String domain ) {
159- DefaultHttpClient .Builder httpBuilder = DefaultHttpClient .newBuilder ()
160- .telemetryEnabled (!telemetryDisabled );
161-
162- if (loggingEnabled ) {
163- httpBuilder .withLogging (new LoggingOptions (LoggingOptions .LogLevel .BODY ));
164- }
165-
166168 return AuthAPI .newBuilder (domain , clientId , clientSecret )
167- .withHttpClient (httpBuilder . build ())
169+ .withHttpClient (getHttpClient ())
168170 .build ();
169171 }
170172
173+ private Auth0HttpClient getHttpClient () {
174+ if (this .httpClient == null ) {
175+ DefaultHttpClient .Builder httpBuilder = DefaultHttpClient .newBuilder ()
176+ .telemetryEnabled (!telemetryDisabled );
177+ if (loggingEnabled ) {
178+ httpBuilder .withLogging (new LoggingOptions (LoggingOptions .LogLevel .BODY ));
179+ }
180+ this .httpClient = httpBuilder .build ();
181+ }
182+ return this .httpClient ;
183+ }
184+
171185 /**
172186 * Pre builds an Auth0 Authorize Url with the given redirect URI, state and nonce parameters.
173187 *
0 commit comments