diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/HttpSignatureAuth.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/HttpSignatureAuth.mustache index c978de46a0f..744f9f6bd4b 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/HttpSignatureAuth.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/HttpSignatureAuth.mustache @@ -234,16 +234,12 @@ public class HttpSignatureAuth implements Authentication { throw new ApiException("Signer cannot be null. Please call the method `setPrivateKey` to set it up correctly"); } - // construct the path with the URL query string - String path = uri.getPath(); - - List urlQueries = new ArrayList(); - for (Pair queryParam : queryParams) { - urlQueries.add(queryParam.getName() + "=" + URLEncoder.encode(queryParam.getValue(), "utf8").replaceAll("\\+", "%20")); - } - - if (!urlQueries.isEmpty()) { - path = path + "?" + String.join("&", urlQueries); + // construct the path with the URL-encoded path and query. + // Calling getRawPath and getRawQuery ensures the path is URL-encoded as it will be serialized + // on the wire. The HTTP signature must use the encode URL as it is sent on the wire. + String path = uri.getRawPath(); + if (uri.getRawQuery() != "") { + path += "?" + uri.getRawQuery(); } headerParams.put("Authorization", signer.sign(method, path, headerParams).toString()); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java index 5f0e4dba350..c1222a7fff6 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java @@ -245,16 +245,12 @@ public class HttpSignatureAuth implements Authentication { throw new ApiException("Signer cannot be null. Please call the method `setPrivateKey` to set it up correctly"); } - // construct the path with the URL query string - String path = uri.getPath(); - - List urlQueries = new ArrayList(); - for (Pair queryParam : queryParams) { - urlQueries.add(queryParam.getName() + "=" + URLEncoder.encode(queryParam.getValue(), "utf8").replaceAll("\\+", "%20")); - } - - if (!urlQueries.isEmpty()) { - path = path + "?" + String.join("&", urlQueries); + // construct the path with the URL-encoded path and query. + // Calling getRawPath and getRawQuery ensures the path is URL-encoded as it will be serialized + // on the wire. The HTTP signature must use the encode URL as it is sent on the wire. + String path = uri.getRawPath(); + if (uri.getRawQuery() != "") { + path += "?" + uri.getRawQuery(); } headerParams.put("Authorization", signer.sign(method, path, headerParams).toString());