33import java .io .IOException ;
44import java .util .AbstractMap .SimpleEntry ;
55import java .util .ArrayList ;
6+ import java .util .Collections ;
67import java .util .HashMap ;
78import java .util .HashSet ;
89import java .util .List ;
@@ -79,16 +80,24 @@ private HttpRequest(final GlobalConfiguration coreConfig, final String server,
7980 final ArraySerializationFormat arraySerializationFormat ) throws IOException {
8081 this .coreConfig = coreConfig ;
8182 this .compatibilityFactory = coreConfig .getCompatibilityFactory ();
82- queryUrlBuilder = getStringBuilder (server , path , queryParams , arraySerializationFormat );
83+ HttpHeaders requestHeaders = addHeaders (headerParams );
84+ // Creating a basic request to provide it to auth instances
85+ Request request = buildBasicRequest (httpMethod , requestHeaders );
86+
87+ applyAuthentication (request , authentication );
88+ // include auth query parameters in request query params to have them in the query url
89+ if (request .getQueryParameters () != null ) {
90+ queryParams .putAll (request .getQueryParameters ());
91+ }
8392
93+ queryUrlBuilder = getStringBuilder (server , path , queryParams , arraySerializationFormat );
8494 processTemplateParams (templateParams );
8595 Object bodyValue = buildBody (body , bodySerializer , bodyParameters );
8696 List <SimpleEntry <String , Object >> formFields =
8797 generateFormFields (formParams , formParameters , arraySerializationFormat );
8898 coreHttpRequest =
89- buildRequest (httpMethod , bodyValue , addHeaders ( headerParams ) , queryParams ,
99+ buildRequest (httpMethod , bodyValue , requestHeaders , queryParams ,
90100 formFields , arraySerializationFormat );
91- applyAuthentication (authentication );
92101 }
93102
94103 /**
@@ -111,14 +120,26 @@ private Request buildRequest(
111120 queryParams , formFields );
112121 }
113122
114- private void applyAuthentication (Authentication authentication ) {
123+ /**
124+ * Builds a request with minimal query parameters.
125+ * @param httpMethod The request HTTP verb.
126+ * @param headerParams The request header parameters.
127+ * @return the {@link Request} instance.
128+ */
129+ private Request buildBasicRequest (Method httpMethod , HttpHeaders headerParams )
130+ throws IOException {
131+ return compatibilityFactory .createHttpRequest (httpMethod , null , headerParams ,
132+ new HashMap <String , Object >(), Collections .emptyList ());
133+ }
134+
135+ private void applyAuthentication (Request request , Authentication authentication ) {
115136 if (authentication != null ) {
116137 authentication .validate ();
117138 if (!authentication .isValid ()) {
118139 throw new AuthValidationException (authentication .getErrorMessage ());
119140 }
120141
121- authentication .apply (coreHttpRequest );
142+ authentication .apply (request );
122143 }
123144 }
124145
0 commit comments