From c568f5c869f40dfede70a2c971e7471626a0732a Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 19 Sep 2024 12:03:40 +0530 Subject: [PATCH] fix: pr comment --- .../CreateUpdateOrGetOAuthClientAPI.java | 51 ++++----- .../OAuthAcceptAuthConsentRequestAPI.java | 15 +-- .../oauth/OAuthAcceptAuthLoginRequestAPI.java | 15 +-- .../OAuthAcceptAuthLogoutRequestAPI.java | 25 ++--- .../webserver/api/oauth/OAuthAuthAPI.java | 47 ++++---- .../api/oauth/OAuthClientListAPI.java | 82 +++++++------- .../oauth/OAuthGetAuthConsentRequestAPI.java | 17 ++- .../oauth/OAuthGetAuthLoginRequestAPI.java | 17 ++- .../oauth/OAuthGetAuthLogoutRequestAPI.java | 17 ++- .../webserver/api/oauth/OAuthProxyHelper.java | 101 ++++-------------- .../OAuthRejectAuthConsentRequestAPI.java | 20 ++-- .../oauth/OAuthRejectAuthLoginRequestAPI.java | 18 ++-- .../OAuthRejectAuthLogoutRequestAPI.java | 16 +-- .../webserver/api/oauth/OAuthTokenAPI.java | 33 +++--- .../api/oauth/OAuthTokenIntrospectAPI.java | 24 +++-- .../api/oauth/RemoveOAuthClientAPI.java | 29 ++--- 16 files changed, 240 insertions(+), 287 deletions(-) diff --git a/src/main/java/io/supertokens/webserver/api/oauth/CreateUpdateOrGetOAuthClientAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/CreateUpdateOrGetOAuthClientAPI.java index 3e314fa75..cfc811e8f 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/CreateUpdateOrGetOAuthClientAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/CreateUpdateOrGetOAuthClientAPI.java @@ -56,9 +56,9 @@ public CreateUpdateOrGetOAuthClientAPI(Main main){ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String clientId = InputParser.getQueryParamOrThrowError(req, "clientId", false); - + try { - OAuthProxyHelper.proxyGET( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -67,11 +67,11 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO true, // proxyToAdmin true, // camelToSnakeCaseConversion OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), - new HashMap<>(), // getHeadersForProxy - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - return jsonBody.getAsJsonObject(); - } + new HashMap<>() ); + if (response != null) { + super.sendJsonResponse(200, response.jsonResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } @@ -92,7 +92,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I input.addProperty("owner", appIdentifier.getAppId()); - OAuthProxyHelper.proxyJsonPOST( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPOST( main, req, resp, appIdentifier, storage, @@ -101,20 +101,20 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I true, // proxyToAdmin true, // camelToSnakeCaseConversion input, // jsonBody - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - String clientId = jsonBody.getAsJsonObject().get("clientId").getAsString(); - - try { - OAuth.addClientId(main, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), clientId); - } catch (StorageQueryException | TenantOrAppNotFoundException | BadPermissionException e) { - throw new ServletException(e); - } catch (OAuth2ClientAlreadyExistsForAppException e) { - // ignore - } - return jsonBody.getAsJsonObject(); - } + new HashMap<>() // headers ); + if (response != null) { + String clientId = response.jsonResponse.getAsJsonObject().get("clientId").getAsString(); + + try { + OAuth.addClientId(main, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), clientId); + } catch (StorageQueryException | TenantOrAppNotFoundException | BadPermissionException e) { + throw new ServletException(e); + } catch (OAuth2ClientAlreadyExistsForAppException e) { + // ignore + } + super.sendJsonResponse(200, response.jsonResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } @@ -151,7 +151,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO } try { - OAuthProxyHelper.proxyJsonPUT( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPUT( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -161,11 +161,12 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO true, // camelToSnakeCaseConversion new HashMap<>(), // queryParams input, // jsonBody - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - return jsonBody.getAsJsonObject(); - } + new HashMap<>() // headers ); + + if (response != null) { + super.sendJsonResponse(200, response.jsonResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthConsentRequestAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthConsentRequestAPI.java index 252af8542..3df0236d0 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthConsentRequestAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthConsentRequestAPI.java @@ -7,6 +7,7 @@ import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.webserver.InputParser; @@ -31,7 +32,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject input = InputParser.parseJsonObjectOrThrowError(req); try { - OAuthProxyHelper.proxyJsonPUT( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPUT( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -41,13 +42,13 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO true, // camelToSnakeCaseConversion OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), input, // jsonBody - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - JsonObject response = jsonBody.getAsJsonObject(); - response.addProperty("status", "OK"); - return response; - } + new HashMap<>() // headers ); + + if (response != null) { + response.jsonResponse.getAsJsonObject().addProperty("status", "OK"); + super.sendJsonResponse(200, response.jsonResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthLoginRequestAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthLoginRequestAPI.java index ea73b7bf4..792f01539 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthLoginRequestAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthLoginRequestAPI.java @@ -9,6 +9,7 @@ import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.webserver.WebserverAPI; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.webserver.InputParser; import jakarta.servlet.ServletException; @@ -31,7 +32,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject input = InputParser.parseJsonObjectOrThrowError(req); try { - OAuthProxyHelper.proxyJsonPUT( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPUT( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -41,13 +42,13 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO true, OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), input, // jsonBody - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { - JsonObject response = jsonBody.getAsJsonObject(); - response.addProperty("status", "OK"); - return response; - } + new HashMap<>() // headers ); + + if (response != null) { + response.jsonResponse.getAsJsonObject().addProperty("status", "OK"); + super.sendJsonResponse(200, response.jsonResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthLogoutRequestAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthLogoutRequestAPI.java index c321b50bf..7d07c254d 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthLogoutRequestAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthAcceptAuthLogoutRequestAPI.java @@ -7,6 +7,7 @@ import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.webserver.InputParser; @@ -31,23 +32,23 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject input = InputParser.parseJsonObjectOrThrowError(req); try { - OAuthProxyHelper.proxyJsonPUT( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPUT( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), null, // clientIdToCheck - "/admin/oauth2/auth/requests/logout/accept", - true, - true, - OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), - input, - new HashMap<>(), - (statusCode, headers, rawBody, jsonBody) -> { - JsonObject response = jsonBody.getAsJsonObject(); - response.addProperty("status", "OK"); - return response; - } + "/admin/oauth2/auth/requests/logout/accept", // proxyPath + true, // proxyToAdmin + true, // camelToSnakeCaseConversion + OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), // queryParams + input, // jsonBody + new HashMap<>() // headers ); + + if (response != null) { + response.jsonResponse.getAsJsonObject().addProperty("status", "OK"); + super.sendJsonResponse(200, response.jsonResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthAuthAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthAuthAPI.java index 0662d0405..c7b604801 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthAuthAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthAuthAPI.java @@ -22,6 +22,7 @@ import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.webserver.InputParser; @@ -64,7 +65,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I } try { - OAuthProxyHelper.proxyGET( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -73,30 +74,32 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I false, // proxyToAdmin false, // camelToSnakeCaseConversion queryParams, - headers, - (statusCode, responseHeaders, rawBody, jsonBody) -> { // getJsonResponse - if (headers == null || !responseHeaders.containsKey("Location")) { - throw new IllegalStateException("Invalid response from hydra"); - } - - String redirectTo = responseHeaders.get("Location").get(0); - List responseCookies = responseHeaders.get("Set-Cookie"); - - JsonObject response = new JsonObject(); - response.addProperty("redirectTo", redirectTo); + headers + ); - JsonArray jsonCookies = new JsonArray(); - if (responseCookies != null) { - for (String cookie : responseCookies) { - jsonCookies.add(new JsonPrimitive(cookie)); - } + if (response != null) { + if (response.headers == null || !response.headers.containsKey("Location")) { + throw new IllegalStateException("Invalid response from hydra"); + } + + String redirectTo = response.headers.get("Location").get(0); + List responseCookies = response.headers.get("Set-Cookie"); + + JsonObject finalResponse = new JsonObject(); + finalResponse.addProperty("redirectTo", redirectTo); + + JsonArray jsonCookies = new JsonArray(); + if (responseCookies != null) { + for (String cookie : responseCookies) { + jsonCookies.add(new JsonPrimitive(cookie)); } - - response.add("cookies", jsonCookies); - response.addProperty("status", "OK"); - return response; } - ); + + finalResponse.add("cookies", jsonCookies); + finalResponse.addProperty("status", "OK"); + + super.sendJsonResponse(200, finalResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthClientListAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthClientListAPI.java index 71086161a..00eff45d3 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthClientListAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthClientListAPI.java @@ -13,6 +13,7 @@ import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.oauth.OAuth; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.Storage; @@ -43,7 +44,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO Map queryParams = OAuthProxyHelper.defaultGetQueryParamsFromRequest(req); queryParams.put("owner", appIdentifier.getAppId()); - OAuthProxyHelper.proxyGET( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET( main, req, resp, appIdentifier, storage, @@ -52,56 +53,57 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO true, // proxyToAdmin true, // camelToSnakeCaseConversion queryParams, - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - JsonObject response = new JsonObject(); - response.addProperty("status", "OK"); + new HashMap<>() // headers + ); - // Filter out the clients for app - List clientIds; - try { - clientIds = OAuth.listClientIds(main, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req)); - } catch (StorageQueryException | TenantOrAppNotFoundException | BadPermissionException e) { - throw new ServletException(e); - } + if (response != null) { + JsonObject finalResponse = new JsonObject(); + finalResponse.addProperty("status", "OK"); - Set clientIdsSet = new HashSet<>(clientIds); + // Filter out the clients for app + List clientIds; + try { + clientIds = OAuth.listClientIds(main, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req)); + } catch (StorageQueryException | TenantOrAppNotFoundException | BadPermissionException e) { + throw new ServletException(e); + } - JsonArray clients = new JsonArray(); - - for (JsonElement clientElem : jsonBody.getAsJsonArray()) { - if (clientIdsSet.contains(clientElem.getAsJsonObject().get("clientId").getAsString())) { - clients.add(clientElem); - } + Set clientIdsSet = new HashSet<>(clientIds); + + JsonArray clients = new JsonArray(); + + for (JsonElement clientElem : response.jsonResponse.getAsJsonArray()) { + if (clientIdsSet.contains(clientElem.getAsJsonObject().get("clientId").getAsString())) { + clients.add(clientElem); } + } - response.add("clients", clients); + finalResponse.add("clients", clients); - // pagination - List linkHeader = headers.get("Link"); - if (linkHeader != null && !linkHeader.isEmpty()) { - for (String nextLink : linkHeader.get(0).split(",")) { - if (!nextLink.contains("rel=\"next\"")) { - continue; - } + // pagination + List linkHeader = response.headers.get("Link"); + if (linkHeader != null && !linkHeader.isEmpty()) { + for (String nextLink : linkHeader.get(0).split(",")) { + if (!nextLink.contains("rel=\"next\"")) { + continue; + } - String pageToken = null; - if (nextLink.contains("page_token=")) { - int startIndex = nextLink.indexOf("page_token=") + "page_token=".length(); - int endIndex = nextLink.indexOf('>', startIndex); - if (endIndex != -1) { - pageToken = nextLink.substring(startIndex, endIndex); - } - } - if (pageToken != null) { - response.addProperty("nextPaginationToken", pageToken); + String pageToken = null; + if (nextLink.contains("page_token=")) { + int startIndex = nextLink.indexOf("page_token=") + "page_token=".length(); + int endIndex = nextLink.indexOf('>', startIndex); + if (endIndex != -1) { + pageToken = nextLink.substring(startIndex, endIndex); } } + if (pageToken != null) { + finalResponse.addProperty("nextPaginationToken", pageToken); + } } - - return response; } - ); + + super.sendJsonResponse(200, finalResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthConsentRequestAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthConsentRequestAPI.java index 216073ed6..fa40aec62 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthConsentRequestAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthConsentRequestAPI.java @@ -3,10 +3,9 @@ import java.io.IOException; import java.util.HashMap; -import com.google.gson.JsonObject; - import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.webserver.WebserverAPI; @@ -28,7 +27,7 @@ public String getPath() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { try { - OAuthProxyHelper.proxyGET( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -37,14 +36,14 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO true, // proxyToAdmin true, // camelToSnakeCaseConversion OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - JsonObject response = jsonBody.getAsJsonObject(); - response.addProperty("status", "OK"); - return response; - } + new HashMap<>() // headers ); + if (response != null) { + response.jsonResponse.getAsJsonObject().addProperty("status", "OK"); + super.sendJsonResponse(200, response.jsonResponse, resp); + } + } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthLoginRequestAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthLoginRequestAPI.java index d432e951d..d508369bc 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthLoginRequestAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthLoginRequestAPI.java @@ -3,10 +3,9 @@ import java.io.IOException; import java.util.HashMap; -import com.google.gson.JsonObject; - import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.webserver.WebserverAPI; @@ -28,7 +27,7 @@ public String getPath() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { try { - OAuthProxyHelper.proxyGET( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -37,14 +36,14 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO true, // proxyToAdmin true, // camelToSnakeCaseConversion OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - JsonObject response = jsonBody.getAsJsonObject(); - response.addProperty("status", "OK"); - return response; - } + new HashMap<>() // headers ); + if (response != null) { + response.jsonResponse.getAsJsonObject().addProperty("status", "OK"); + super.sendJsonResponse(200, response.jsonResponse, resp); + } + } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthLogoutRequestAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthLogoutRequestAPI.java index a6e168825..ad174654c 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthLogoutRequestAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthGetAuthLogoutRequestAPI.java @@ -3,10 +3,9 @@ import java.io.IOException; import java.util.HashMap; -import com.google.gson.JsonObject; - import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.webserver.WebserverAPI; @@ -28,7 +27,7 @@ public String getPath() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { try { - OAuthProxyHelper.proxyGET( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -37,14 +36,14 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO true, // proxyToAdmin true, // camelToSnakeCaseConversion OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - JsonObject response = jsonBody.getAsJsonObject(); - response.addProperty("status", "OK"); - return response; - } + new HashMap<>() // headers ); + if (response != null) { + response.jsonResponse.getAsJsonObject().addProperty("status", "OK"); + super.sendJsonResponse(200, response.jsonResponse, resp); + } + } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthProxyHelper.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthProxyHelper.java index e71dedb53..3a30544d9 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthProxyHelper.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthProxyHelper.java @@ -5,10 +5,8 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.HashMap; -import java.util.List; import java.util.Map; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.supertokens.Main; @@ -30,22 +28,11 @@ public class OAuthProxyHelper { @Serial private static final long serialVersionUID = -8734479943734920904L; - public static void proxyGET(Main main, HttpServletRequest req, HttpServletResponse resp, AppIdentifier appIdentifier, Storage storage, + public static HttpRequestForOry.Response proxyGET(Main main, HttpServletRequest req, HttpServletResponse resp, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, - Map queryParams, Map headers, - GetJsonResponse getJsonResponse) throws IOException, ServletException { + Map queryParams, Map headers) throws IOException, ServletException { try { - HttpRequestForOry.Response response = OAuth.doOAuthProxyGET(main, appIdentifier, storage, clientIdToCheck, path, proxyToAdmin, camelToSnakeCaseConversion, queryParams, headers); - - JsonObject jsonResponse = getJsonResponse.apply( - response.statusCode, - response.headers, - response.rawResponse, - response.jsonResponse - ); - resp.setStatus(200); - resp.setHeader("Content-Type", "application/json; charset=UTF-8"); - resp.getWriter().println(jsonResponse.toString()); + return OAuth.doOAuthProxyGET(main, appIdentifier, storage, clientIdToCheck, path, proxyToAdmin, camelToSnakeCaseConversion, queryParams, headers); } catch (OAuthClientNotFoundException e) { handleOAuthClientNotFoundException(resp); @@ -54,25 +41,14 @@ public static void proxyGET(Main main, HttpServletRequest req, HttpServletRespon } catch (StorageQueryException | TenantOrAppNotFoundException | FeatureNotEnabledException | InvalidConfigException e) { throw new ServletException(e); } + return null; } - public static void proxyFormPOST(Main main, HttpServletRequest req, HttpServletResponse resp, AppIdentifier appIdentifier, Storage storage, + public static HttpRequestForOry.Response proxyFormPOST(Main main, HttpServletRequest req, HttpServletResponse resp, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, - Map formFields, Map headers, - GetJsonResponse getJsonResponse) throws IOException, ServletException { + Map formFields, Map headers) throws IOException, ServletException { try { - HttpRequestForOry.Response response = OAuth.doOAuthProxyFormPOST(main, appIdentifier, storage, clientIdToCheck, path, proxyToAdmin, camelToSnakeCaseConversion, formFields, headers); - - JsonObject jsonResponse = getJsonResponse.apply( - response.statusCode, - response.headers, - response.rawResponse, - response.jsonResponse - ); - resp.setStatus(200); - resp.setHeader("Content-Type", "application/json; charset=UTF-8"); - resp.getWriter().println(jsonResponse.toString()); - + return OAuth.doOAuthProxyFormPOST(main, appIdentifier, storage, clientIdToCheck, path, proxyToAdmin, camelToSnakeCaseConversion, formFields, headers); } catch (OAuthClientNotFoundException e) { handleOAuthClientNotFoundException(resp); } catch (OAuthAPIException e) { @@ -80,25 +56,14 @@ public static void proxyFormPOST(Main main, HttpServletRequest req, HttpServletR } catch (StorageQueryException | TenantOrAppNotFoundException | FeatureNotEnabledException | InvalidConfigException e) { throw new ServletException(e); } + return null; } - public static void proxyJsonPOST(Main main, HttpServletRequest req, HttpServletResponse resp, AppIdentifier appIdentifier, Storage storage, + public static HttpRequestForOry.Response proxyJsonPOST(Main main, HttpServletRequest req, HttpServletResponse resp, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, - JsonObject jsonInput, Map headers, - GetJsonResponse getJsonResponse) throws IOException, ServletException { + JsonObject jsonInput, Map headers) throws IOException, ServletException { try { - HttpRequestForOry.Response response = OAuth.doOAuthProxyJsonPOST(main, appIdentifier, storage, clientIdToCheck, path, proxyToAdmin, camelToSnakeCaseConversion, jsonInput, headers); - - JsonObject jsonResponse = getJsonResponse.apply( - response.statusCode, - response.headers, - response.rawResponse, - response.jsonResponse - ); - resp.setStatus(200); - resp.setHeader("Content-Type", "application/json; charset=UTF-8"); - resp.getWriter().println(jsonResponse.toString()); - + return OAuth.doOAuthProxyJsonPOST(main, appIdentifier, storage, clientIdToCheck, path, proxyToAdmin, camelToSnakeCaseConversion, jsonInput, headers); } catch (OAuthClientNotFoundException e) { handleOAuthClientNotFoundException(resp); } catch (OAuthAPIException e) { @@ -106,26 +71,15 @@ public static void proxyJsonPOST(Main main, HttpServletRequest req, HttpServletR } catch (StorageQueryException | TenantOrAppNotFoundException | FeatureNotEnabledException | InvalidConfigException e) { throw new ServletException(e); } + return null; } - public static void proxyJsonPUT(Main main, HttpServletRequest req, HttpServletResponse resp, AppIdentifier appIdentifier, Storage storage, + public static HttpRequestForOry.Response proxyJsonPUT(Main main, HttpServletRequest req, HttpServletResponse resp, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, - Map queryParams, JsonObject jsonInput, - Map headers, GetJsonResponse getJsonResponse) throws IOException, ServletException { + Map queryParams, JsonObject jsonInput, Map headers) throws IOException, ServletException { try { - HttpRequestForOry.Response response = OAuth.doOAuthProxyJsonPUT(main, appIdentifier, storage, clientIdToCheck, path, proxyToAdmin, camelToSnakeCaseConversion, queryParams, jsonInput, headers); - - JsonObject jsonResponse = getJsonResponse.apply( - response.statusCode, - response.headers, - response.rawResponse, - response.jsonResponse - ); - resp.setStatus(200); - resp.setHeader("Content-Type", "application/json; charset=UTF-8"); - resp.getWriter().println(jsonResponse.toString()); - + return OAuth.doOAuthProxyJsonPUT(main, appIdentifier, storage, clientIdToCheck, path, proxyToAdmin, camelToSnakeCaseConversion, queryParams, jsonInput, headers); } catch (OAuthClientNotFoundException e) { handleOAuthClientNotFoundException(resp); } catch (OAuthAPIException e) { @@ -133,25 +87,14 @@ public static void proxyJsonPUT(Main main, HttpServletRequest req, HttpServletRe } catch (StorageQueryException | TenantOrAppNotFoundException | FeatureNotEnabledException | InvalidConfigException e) { throw new ServletException(e); } + return null; } - public static void proxyJsonDELETE(Main main, HttpServletRequest req, HttpServletResponse resp, AppIdentifier appIdentifier, Storage storage, + public static HttpRequestForOry.Response proxyJsonDELETE(Main main, HttpServletRequest req, HttpServletResponse resp, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, - JsonObject jsonInput, Map headers, - GetJsonResponse getJsonResponse) throws IOException, ServletException { + JsonObject jsonInput, Map headers) throws IOException, ServletException { try { - HttpRequestForOry.Response response = OAuth.doOAuthProxyJsonDELETE(main, appIdentifier, storage, clientIdToCheck, path, proxyToAdmin, camelToSnakeCaseConversion, jsonInput, headers); - - JsonObject jsonResponse = getJsonResponse.apply( - response.statusCode, - response.headers, - response.rawResponse, - response.jsonResponse - ); - resp.setStatus(200); - resp.setHeader("Content-Type", "application/json; charset=UTF-8"); - resp.getWriter().println(jsonResponse.toString()); - + return OAuth.doOAuthProxyJsonDELETE(main, appIdentifier, storage, clientIdToCheck, path, proxyToAdmin, camelToSnakeCaseConversion, jsonInput, headers); } catch (OAuthClientNotFoundException e) { handleOAuthClientNotFoundException(resp); } catch (OAuthAPIException e) { @@ -159,6 +102,7 @@ public static void proxyJsonDELETE(Main main, HttpServletRequest req, HttpServle } catch (StorageQueryException | TenantOrAppNotFoundException | FeatureNotEnabledException | InvalidConfigException e) { throw new ServletException(e); } + return null; } public static Map defaultGetQueryParamsFromRequest(HttpServletRequest req) { @@ -178,11 +122,6 @@ public static Map defaultGetQueryParamsFromRequest(HttpServletRe return queryParams; } - @FunctionalInterface - public interface GetJsonResponse { - JsonObject apply(int statusCode, Map> headers, String rawBody, JsonElement jsonBody) throws IOException, ServletException; - } - private static void handleOAuthClientNotFoundException(HttpServletResponse resp) throws IOException { JsonObject response = new JsonObject(); response.addProperty("status", "CLIENT_NOT_FOUND_ERROR"); diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthConsentRequestAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthConsentRequestAPI.java index 0fffe2c53..ef4fed870 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthConsentRequestAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthConsentRequestAPI.java @@ -7,6 +7,7 @@ import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.webserver.InputParser; @@ -31,7 +32,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject input = InputParser.parseJsonObjectOrThrowError(req); try { - OAuthProxyHelper.proxyJsonPUT( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPUT( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -39,15 +40,16 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO "/admin/oauth2/auth/requests/consent/reject", // proxyPath true, // proxyToAdmin true, // camelToSnakeCaseConversion - OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), - input, // getJsonBody - new HashMap<>(), // getHeadersForProxy - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - JsonObject response = jsonBody.getAsJsonObject(); - response.addProperty("status", "OK"); - return response; - } + OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), // queryParams + input, // jsonBody + new HashMap<>() // headers ); + + if (response != null) { + response.jsonResponse.getAsJsonObject().addProperty("status", "OK"); + super.sendJsonResponse(200, response.jsonResponse, resp); + } + } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthLoginRequestAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthLoginRequestAPI.java index 490bb1827..6462d358c 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthLoginRequestAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthLoginRequestAPI.java @@ -8,6 +8,7 @@ import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.webserver.InputParser; @@ -32,7 +33,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject input = InputParser.parseJsonObjectOrThrowError(req); try { - OAuthProxyHelper.proxyJsonPUT( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPUT( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -40,15 +41,16 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO "/admin/oauth2/auth/requests/login/reject", // proxyPath true, // proxyToAdmin true, // camelToSnakeCaseConversion - OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), + OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), // queryParams input, // jsonBody - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - JsonObject response = jsonBody.getAsJsonObject(); - response.addProperty("status", "OK"); - return response; - } + new HashMap<>() // headers ); + + if (response != null) { + response.jsonResponse.getAsJsonObject().addProperty("status", "OK"); + super.sendJsonResponse(200, response.jsonResponse, resp); + } + } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthLogoutRequestAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthLogoutRequestAPI.java index 8dacafc16..10252c230 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthLogoutRequestAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthRejectAuthLogoutRequestAPI.java @@ -7,6 +7,7 @@ import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.webserver.InputParser; @@ -31,7 +32,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject input = InputParser.parseJsonObjectOrThrowError(req); try { - OAuthProxyHelper.proxyJsonPUT( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPUT( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -41,13 +42,14 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO true, // camelToSnakeCaseConversion OAuthProxyHelper.defaultGetQueryParamsFromRequest(req), input, // jsonBody - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - JsonObject response = jsonBody.getAsJsonObject(); - response.addProperty("status", "OK"); - return response; - } + new HashMap<>() // headers ); + + if (response != null) { + response.jsonResponse.getAsJsonObject().addProperty("status", "OK"); + super.sendJsonResponse(200, response.jsonResponse, resp); + } + } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthTokenAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthTokenAPI.java index 8660cddde..22a479c6a 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthTokenAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthTokenAPI.java @@ -21,6 +21,7 @@ import io.supertokens.Main; import io.supertokens.jwt.exceptions.UnsupportedJWTSigningAlgorithmException; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.oauth.OAuth; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.Storage; @@ -73,7 +74,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I } try { - OAuthProxyHelper.proxyFormPOST( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyFormPOST( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -82,26 +83,22 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I false, // proxyToAdmin false, // camelToSnakeCaseConversion formFields, - new HashMap<>(), // headers - (statusCode, headers, rawBody, jsonBody) -> { - if (jsonBody == null) { - throw new IllegalStateException("unexpected response from hydra"); - } - - try { - AppIdentifier appIdentifier = getAppIdentifier(req); - Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req); + new HashMap<>() // headers + ); - jsonBody = OAuth.transformTokens(super.main, appIdentifier, storage, jsonBody.getAsJsonObject(), iss, accessTokenUpdate, idTokenUpdate, useDynamicKey); - - } catch (IOException | InvalidConfigException | TenantOrAppNotFoundException | BadPermissionException | StorageQueryException | InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException | JWTCreationException | JWTException | StorageTransactionLogicException | UnsupportedJWTSigningAlgorithmException e) { - throw new ServletException(e); - } + if (response != null) { + try { + AppIdentifier appIdentifier = getAppIdentifier(req); + Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req); - jsonBody.getAsJsonObject().addProperty("status", "OK"); - return jsonBody.getAsJsonObject(); + response.jsonResponse = OAuth.transformTokens(super.main, appIdentifier, storage, response.jsonResponse.getAsJsonObject(), iss, accessTokenUpdate, idTokenUpdate, useDynamicKey); + } catch (IOException | InvalidConfigException | TenantOrAppNotFoundException | BadPermissionException | StorageQueryException | InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException | JWTCreationException | JWTException | StorageTransactionLogicException | UnsupportedJWTSigningAlgorithmException e) { + throw new ServletException(e); } - ); + + response.jsonResponse.getAsJsonObject().addProperty("status", "OK"); + super.sendJsonResponse(200, response.jsonResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/OAuthTokenIntrospectAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/OAuthTokenIntrospectAPI.java index b24ca17cf..902e7de83 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/OAuthTokenIntrospectAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/OAuthTokenIntrospectAPI.java @@ -20,6 +20,7 @@ import io.supertokens.Main; import io.supertokens.jwt.exceptions.UnsupportedJWTSigningAlgorithmException; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.oauth.OAuth; import io.supertokens.oauth.Transformations; import io.supertokens.pluginInterface.RECIPE_ID; @@ -63,7 +64,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I } try { - OAuthProxyHelper.proxyFormPOST( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyFormPOST( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -71,18 +72,19 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I "/admin/oauth2/introspect", // pathProxy true, // proxyToAdmin false, // camelToSnakeCaseConversion - formFields, - new HashMap<>(), // getHeaders - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - JsonObject response = jsonBody.getAsJsonObject(); + formFields, // formFields + new HashMap<>() // headers + ); - response.addProperty("iss", iss); - Transformations.transformExt(response); + if (response != null) { + JsonObject finalResponse = response.jsonResponse.getAsJsonObject(); - response.addProperty("status", "OK"); - return response; - } - ); + finalResponse.addProperty("iss", iss); + Transformations.transformExt(finalResponse); + + finalResponse.addProperty("status", "OK"); + super.sendJsonResponse(200, finalResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } diff --git a/src/main/java/io/supertokens/webserver/api/oauth/RemoveOAuthClientAPI.java b/src/main/java/io/supertokens/webserver/api/oauth/RemoveOAuthClientAPI.java index a31fb16f4..9e7f00c9b 100644 --- a/src/main/java/io/supertokens/webserver/api/oauth/RemoveOAuthClientAPI.java +++ b/src/main/java/io/supertokens/webserver/api/oauth/RemoveOAuthClientAPI.java @@ -24,6 +24,7 @@ import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.oauth.HttpRequestForOry; import io.supertokens.oauth.OAuth; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -51,7 +52,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I String clientId = InputParser.parseStringOrThrowError(input, "clientId", false); try { - OAuthProxyHelper.proxyJsonDELETE( + HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonDELETE( main, req, resp, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), @@ -59,20 +60,22 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I "/admin/clients/" + clientId, // proxyPath true, // proxyToAdmin true, // camelToSnakeCaseConversion - new JsonObject(), // getJsonBody - new HashMap<>(), // getHeadersForProxy - (statusCode, headers, rawBody, jsonBody) -> { // getJsonResponse - try { - OAuth.removeClientId(main, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), clientId); - } catch (StorageQueryException | TenantOrAppNotFoundException | BadPermissionException e) { - throw new ServletException(e); - } + new JsonObject(), // jsonBody + new HashMap<>() // headers + ); - JsonObject response = new JsonObject(); - response.addProperty("status", "OK"); - return response; + if (response != null) { + try { + OAuth.removeClientId(main, getAppIdentifier(req), enforcePublicTenantAndGetPublicTenantStorage(req), clientId); + } catch (StorageQueryException | TenantOrAppNotFoundException | BadPermissionException e) { + throw new ServletException(e); } - ); + + JsonObject finalResponse = new JsonObject(); + finalResponse.addProperty("status", "OK"); + + super.sendJsonResponse(200, finalResponse, resp); + } } catch (IOException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e);