Skip to content

Commit

Permalink
fix: rename to oauthprovider and add client crud tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Oct 15, 2024
1 parent 9213fd4 commit ec75e62
Show file tree
Hide file tree
Showing 28 changed files with 1,011 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Map;
import java.util.stream.Collectors;

public class HttpRequestForOry {
public class HttpRequestForOAuthProvider {
// This is a helper class to make HTTP requests to the hydra server specifically.
// Although this is similar to HttpRequest, this is slightly modified to be able to work with
// form data, headers in request and responses, query params in non-get requests, reading responses in
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/io/supertokens/oauth/OAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static void checkForOauthFeature(AppIdentifier appIdentifier, Main main)
"feature.");
}

public static HttpRequestForOry.Response doOAuthProxyGET(Main main, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, Map<String, String> queryParams, Map<String, String> headers) throws StorageQueryException, OAuthClientNotFoundException, TenantOrAppNotFoundException, FeatureNotEnabledException, InvalidConfigException, IOException, OAuthAPIException {
public static HttpRequestForOAuthProvider.Response doOAuthProxyGET(Main main, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, Map<String, String> queryParams, Map<String, String> headers) throws StorageQueryException, OAuthClientNotFoundException, TenantOrAppNotFoundException, FeatureNotEnabledException, InvalidConfigException, IOException, OAuthAPIException {
checkForOauthFeature(appIdentifier, main);
OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage);

Expand All @@ -97,7 +97,7 @@ public static HttpRequestForOry.Response doOAuthProxyGET(Main main, AppIdentifie
}
String fullUrl = baseURL + path;

HttpRequestForOry.Response response = HttpRequestForOry.doGet(fullUrl, headers, queryParams);
HttpRequestForOAuthProvider.Response response = HttpRequestForOAuthProvider.doGet(fullUrl, headers, queryParams);

// Response transformations
response.jsonResponse = Transformations.transformJsonResponseFromHydra(main, appIdentifier, response.jsonResponse);
Expand All @@ -113,7 +113,7 @@ public static HttpRequestForOry.Response doOAuthProxyGET(Main main, AppIdentifie
return response;
}

public static HttpRequestForOry.Response doOAuthProxyFormPOST(Main main, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, Map<String, String> formFields, Map<String, String> headers) throws StorageQueryException, OAuthClientNotFoundException, TenantOrAppNotFoundException, FeatureNotEnabledException, InvalidConfigException, IOException, OAuthAPIException {
public static HttpRequestForOAuthProvider.Response doOAuthProxyFormPOST(Main main, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, Map<String, String> formFields, Map<String, String> headers) throws StorageQueryException, OAuthClientNotFoundException, TenantOrAppNotFoundException, FeatureNotEnabledException, InvalidConfigException, IOException, OAuthAPIException {
checkForOauthFeature(appIdentifier, main);
OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage);

Expand All @@ -137,7 +137,7 @@ public static HttpRequestForOry.Response doOAuthProxyFormPOST(Main main, AppIden
}
String fullUrl = baseURL + path;

HttpRequestForOry.Response response = HttpRequestForOry.doFormPost(fullUrl, headers, formFields);
HttpRequestForOAuthProvider.Response response = HttpRequestForOAuthProvider.doFormPost(fullUrl, headers, formFields);

// Response transformations
response.jsonResponse = Transformations.transformJsonResponseFromHydra(main, appIdentifier, response.jsonResponse);
Expand All @@ -152,7 +152,7 @@ public static HttpRequestForOry.Response doOAuthProxyFormPOST(Main main, AppIden
return response;
}

public static HttpRequestForOry.Response doOAuthProxyJsonPOST(Main main, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, JsonObject jsonInput, Map<String, String> headers) throws StorageQueryException, OAuthClientNotFoundException, TenantOrAppNotFoundException, FeatureNotEnabledException, InvalidConfigException, IOException, OAuthAPIException {
public static HttpRequestForOAuthProvider.Response doOAuthProxyJsonPOST(Main main, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, JsonObject jsonInput, Map<String, String> headers) throws StorageQueryException, OAuthClientNotFoundException, TenantOrAppNotFoundException, FeatureNotEnabledException, InvalidConfigException, IOException, OAuthAPIException {
checkForOauthFeature(appIdentifier, main);
OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage);

Expand All @@ -176,7 +176,7 @@ public static HttpRequestForOry.Response doOAuthProxyJsonPOST(Main main, AppIden
}
String fullUrl = baseURL + path;

HttpRequestForOry.Response response = HttpRequestForOry.doJsonPost(fullUrl, headers, jsonInput);
HttpRequestForOAuthProvider.Response response = HttpRequestForOAuthProvider.doJsonPost(fullUrl, headers, jsonInput);

// Response transformations
response.jsonResponse = Transformations.transformJsonResponseFromHydra(main, appIdentifier, response.jsonResponse);
Expand All @@ -191,7 +191,7 @@ public static HttpRequestForOry.Response doOAuthProxyJsonPOST(Main main, AppIden
return response;
}

public static HttpRequestForOry.Response doOAuthProxyJsonPUT(Main main, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, Map<String, String> queryParams, JsonObject jsonInput, Map<String, String> headers) throws StorageQueryException, OAuthClientNotFoundException, TenantOrAppNotFoundException, FeatureNotEnabledException, InvalidConfigException, IOException, OAuthAPIException {
public static HttpRequestForOAuthProvider.Response doOAuthProxyJsonPUT(Main main, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, Map<String, String> queryParams, JsonObject jsonInput, Map<String, String> headers) throws StorageQueryException, OAuthClientNotFoundException, TenantOrAppNotFoundException, FeatureNotEnabledException, InvalidConfigException, IOException, OAuthAPIException {
checkForOauthFeature(appIdentifier, main);
OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage);

Expand All @@ -216,7 +216,7 @@ public static HttpRequestForOry.Response doOAuthProxyJsonPUT(Main main, AppIdent
}
String fullUrl = baseURL + path;

HttpRequestForOry.Response response = HttpRequestForOry.doJsonPut(fullUrl, queryParams, headers, jsonInput);
HttpRequestForOAuthProvider.Response response = HttpRequestForOAuthProvider.doJsonPut(fullUrl, queryParams, headers, jsonInput);

// Response transformations
response.jsonResponse = Transformations.transformJsonResponseFromHydra(main, appIdentifier, response.jsonResponse);
Expand All @@ -231,7 +231,7 @@ public static HttpRequestForOry.Response doOAuthProxyJsonPUT(Main main, AppIdent
return response;
}

public static HttpRequestForOry.Response doOAuthProxyJsonDELETE(Main main, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, Map<String, String> queryParams, JsonObject jsonInput, Map<String, String> headers) throws StorageQueryException, OAuthClientNotFoundException, TenantOrAppNotFoundException, FeatureNotEnabledException, InvalidConfigException, IOException, OAuthAPIException {
public static HttpRequestForOAuthProvider.Response doOAuthProxyJsonDELETE(Main main, AppIdentifier appIdentifier, Storage storage, String clientIdToCheck, String path, boolean proxyToAdmin, boolean camelToSnakeCaseConversion, Map<String, String> queryParams, JsonObject jsonInput, Map<String, String> headers) throws StorageQueryException, OAuthClientNotFoundException, TenantOrAppNotFoundException, FeatureNotEnabledException, InvalidConfigException, IOException, OAuthAPIException {
checkForOauthFeature(appIdentifier, main);
OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage);

Expand All @@ -255,7 +255,7 @@ public static HttpRequestForOry.Response doOAuthProxyJsonDELETE(Main main, AppId
}
String fullUrl = baseURL + path;

HttpRequestForOry.Response response = HttpRequestForOry.doJsonDelete(fullUrl, queryParams, headers, jsonInput);
HttpRequestForOAuthProvider.Response response = HttpRequestForOAuthProvider.doJsonDelete(fullUrl, queryParams, headers, jsonInput);

// Response transformations
response.jsonResponse = Transformations.transformJsonResponseFromHydra(main, appIdentifier, response.jsonResponse);
Expand All @@ -270,7 +270,7 @@ public static HttpRequestForOry.Response doOAuthProxyJsonDELETE(Main main, AppId
return response;
}

private static void checkNonSuccessResponse(HttpRequestForOry.Response response) throws OAuthAPIException, OAuthClientNotFoundException {
private static void checkNonSuccessResponse(HttpRequestForOAuthProvider.Response response) throws OAuthAPIException, OAuthClientNotFoundException {
if (response.statusCode == 404) {
throw new OAuthClientNotFoundException();
}
Expand Down Expand Up @@ -381,9 +381,9 @@ private static String decryptClientSecret(Main main, String clientSecret) throws
return clientSecret;
}

public static void removeClient(Main main, AppIdentifier appIdentifier, Storage storage, String clientId) throws StorageQueryException {
public static boolean removeClient(Main main, AppIdentifier appIdentifier, Storage storage, String clientId) throws StorageQueryException {
OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage);
oauthStorage.deleteOAuthClient(appIdentifier, clientId);
return oauthStorage.deleteOAuthClient(appIdentifier, clientId);
}

public static List<OAuthClient> getClients(Main main, AppIdentifier appIdentifier, Storage storage, List<String> clientIds) throws StorageQueryException, InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, InvalidConfigException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import io.supertokens.Main;
import io.supertokens.featureflag.exceptions.FeatureNotEnabledException;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.oauth.HttpRequestForOry;
import io.supertokens.oauth.HttpRequestForOAuthProvider;
import io.supertokens.oauth.OAuth;
import io.supertokens.oauth.Transformations;
import io.supertokens.oauth.exceptions.OAuthAPIException;
Expand Down Expand Up @@ -71,7 +71,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO
try {
AppIdentifier appIdentifier = getAppIdentifier(req);
Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req);
HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET(
HttpRequestForOAuthProvider.Response response = OAuthProxyHelper.proxyGET(
main, req, resp,
appIdentifier,
storage,
Expand Down Expand Up @@ -132,7 +132,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I

input.addProperty("owner", appIdentifier.getAppId());

HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPOST(
HttpRequestForOAuthProvider.Response response = OAuthProxyHelper.proxyJsonPOST(
main, req, resp,
appIdentifier,
storage,
Expand Down Expand Up @@ -175,7 +175,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO
try {
Map<String, String> queryParams = new HashMap<>();
queryParams.put("clientId", clientId);
HttpRequestForOry.Response response = OAuth.doOAuthProxyGET(
HttpRequestForOAuthProvider.Response response = OAuth.doOAuthProxyGET(
main,
getAppIdentifier(req),
enforcePublicTenantAndGetPublicTenantStorage(req),
Expand Down Expand Up @@ -219,7 +219,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO
client = new OAuthClient(clientId, client.clientSecret, client.isClientCredentialsOnly, enableRefreshTokenRotation);
}

HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPUT(
HttpRequestForOAuthProvider.Response response = OAuthProxyHelper.proxyJsonPUT(
main, req, resp,
appIdentifier,
storage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import io.supertokens.Main;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.oauth.HttpRequestForOry;
import io.supertokens.oauth.HttpRequestForOAuthProvider;
import io.supertokens.pluginInterface.RECIPE_ID;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.webserver.InputParser;
Expand Down Expand Up @@ -63,7 +63,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO
input.add("session", session);

try {
HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPUT(
HttpRequestForOAuthProvider.Response response = OAuthProxyHelper.proxyJsonPUT(
main, req, resp,
getAppIdentifier(req),
enforcePublicTenantAndGetPublicTenantStorage(req),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import com.google.gson.JsonObject;

import io.supertokens.Main;
import io.supertokens.oauth.HttpRequestForOAuthProvider;
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;
Expand All @@ -32,7 +32,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO
JsonObject input = InputParser.parseJsonObjectOrThrowError(req);

try {
HttpRequestForOry.Response response = OAuthProxyHelper.proxyJsonPUT(
HttpRequestForOAuthProvider.Response response = OAuthProxyHelper.proxyJsonPUT(
main, req, resp,
getAppIdentifier(req),
enforcePublicTenantAndGetPublicTenantStorage(req),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.supertokens.webserver.api.oauth;

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.oauth.OAuth;
import io.supertokens.oauth.exceptions.OAuthAPIException;
import io.supertokens.pluginInterface.RECIPE_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.supertokens.ActiveUsers;
import io.supertokens.Main;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.oauth.HttpRequestForOry;
import io.supertokens.oauth.HttpRequestForOAuthProvider;
import io.supertokens.oauth.OAuth;
import io.supertokens.oauth.OAuthToken;
import io.supertokens.pluginInterface.RECIPE_ID;
Expand Down Expand Up @@ -86,7 +86,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
AppIdentifier appIdentifier = getAppIdentifier(req);
Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req);

HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET(
HttpRequestForOAuthProvider.Response response = OAuthProxyHelper.proxyGET(
main, req, resp,
appIdentifier,
storage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import io.supertokens.Main;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.oauth.HttpRequestForOry;
import io.supertokens.oauth.HttpRequestForOAuthProvider;
import io.supertokens.oauth.OAuth;
import io.supertokens.pluginInterface.RECIPE_ID;
import io.supertokens.pluginInterface.Storage;
Expand Down Expand Up @@ -53,7 +53,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO
Map<String, String> queryParams = OAuthProxyHelper.defaultGetQueryParamsFromRequest(req);
queryParams.put("owner", appIdentifier.getAppId());

HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET(
HttpRequestForOAuthProvider.Response response = OAuthProxyHelper.proxyGET(
main, req, resp,
appIdentifier,
storage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import io.supertokens.Main;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.oauth.HttpRequestForOry;
import io.supertokens.oauth.HttpRequestForOAuthProvider;
import io.supertokens.oauth.Transformations;
import io.supertokens.pluginInterface.RECIPE_ID;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
Expand All @@ -28,7 +28,7 @@ public String getPath() {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
try {
HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET(
HttpRequestForOAuthProvider.Response response = OAuthProxyHelper.proxyGET(
main, req, resp,
getAppIdentifier(req),
enforcePublicTenantAndGetPublicTenantStorage(req),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import io.supertokens.Main;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.oauth.HttpRequestForOry;
import io.supertokens.oauth.HttpRequestForOAuthProvider;
import io.supertokens.oauth.Transformations;
import io.supertokens.pluginInterface.RECIPE_ID;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
Expand All @@ -28,7 +28,7 @@ public String getPath() {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
try {
HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET(
HttpRequestForOAuthProvider.Response response = OAuthProxyHelper.proxyGET(
main, req, resp,
getAppIdentifier(req),
enforcePublicTenantAndGetPublicTenantStorage(req),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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.HttpRequestForOAuthProvider;
import io.supertokens.oauth.OAuth;
import io.supertokens.oauth.exceptions.OAuthAPIException;
import io.supertokens.pluginInterface.RECIPE_ID;
Expand Down Expand Up @@ -77,7 +77,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO

// Check if the post logout redirection URI is valid for the clientId
if (postLogoutRedirectionUri != null) {
HttpRequestForOry.Response response = OAuthProxyHelper.proxyGET(
HttpRequestForOAuthProvider.Response response = OAuthProxyHelper.proxyGET(
main, req, resp,
appIdentifier, storage,
clientId, // clientIdToCheck
Expand Down
Loading

0 comments on commit ec75e62

Please sign in to comment.