Skip to content

Commit

Permalink
Move setting of authentication parameters before generating target UR…
Browse files Browse the repository at this point in the history
…L to consider API keys in URL parameters
  • Loading branch information
jheyens committed Feb 19, 2025
1 parent 9374dbd commit 790bc5e
Show file tree
Hide file tree
Showing 146 changed files with 6,949 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,27 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
{{#hasHttpSignatureMethods}}
serializeToString(body, formParams, contentType, isBodyNullable),
{{/hasHttpSignatureMethods}}
{{^hasHttpSignatureMethods}}
null,
{{/hasHttpSignatureMethods}}
method,
target.getUri());
}

if (queryParams != null) {
for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) {
Expand Down Expand Up @@ -1262,27 +1283,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {

Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
{{#hasHttpSignatureMethods}}
serializeToString(body, formParams, contentType, isBodyNullable),
{{/hasHttpSignatureMethods}}
{{^hasHttpSignatureMethods}}
null,
{{/hasHttpSignatureMethods}}
method,
target.getUri());
}

for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue();
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,22 @@ public <T> ApiResponse<T> invokeAPI(
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

if (queryParams != null) {
for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) {
Expand Down Expand Up @@ -1041,22 +1057,6 @@ public <T> ApiResponse<T> invokeAPI(

Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue();
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,22 @@ public <T> ApiResponse<T> invokeAPI(
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

if (queryParams != null) {
for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) {
Expand Down Expand Up @@ -1041,22 +1057,6 @@ public <T> ApiResponse<T> invokeAPI(

Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue();
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,22 @@ public <T> ApiResponse<T> invokeAPI(
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

if (queryParams != null) {
for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) {
Expand Down Expand Up @@ -1182,22 +1198,6 @@ public <T> ApiResponse<T> invokeAPI(

Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue();
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,22 @@ public <T> ApiResponse<T> invokeAPI(
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

if (queryParams != null) {
for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) {
Expand Down Expand Up @@ -1182,22 +1198,6 @@ public <T> ApiResponse<T> invokeAPI(

Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue();
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,22 @@ public <T> ApiResponse<T> invokeAPI(
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

if (queryParams != null) {
for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) {
Expand Down Expand Up @@ -1090,22 +1106,6 @@ public <T> ApiResponse<T> invokeAPI(

Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue();
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,22 @@ public <T> ApiResponse<T> invokeAPI(
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

if (queryParams != null) {
for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) {
Expand Down Expand Up @@ -1041,22 +1057,6 @@ public <T> ApiResponse<T> invokeAPI(

Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue();
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,22 @@ public <T> ApiResponse<T> invokeAPI(
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

if (queryParams != null) {
for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) {
Expand Down Expand Up @@ -1166,22 +1182,6 @@ public <T> ApiResponse<T> invokeAPI(

Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);

// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue();
if (value != null) {
Expand Down
Loading

0 comments on commit 790bc5e

Please sign in to comment.