From 0e1075e2d36327ae6d3177679fbb671330000890 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Wed, 2 Oct 2024 16:46:38 +0530 Subject: [PATCH] fix: rename / refactor --- .../java/io/supertokens/ee/EEFeatureFlag.java | 8 +- .../CleanupOAuthRevokeListAndChallenges.java | 7 +- .../java/io/supertokens/inmemorydb/Start.java | 81 ++++++++++--------- .../inmemorydb/queries/OAuthQueries.java | 50 ++++++------ src/main/java/io/supertokens/oauth/OAuth.java | 45 ++++++----- .../test/multitenant/TestAppData.java | 2 +- 6 files changed, 96 insertions(+), 97 deletions(-) diff --git a/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java b/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java index 824014f03..8825a765d 100644 --- a/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java +++ b/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java @@ -356,15 +356,15 @@ private JsonObject getOAuthStats() throws StorageQueryException, TenantOrAppNotF OAuthStorage oAuthStorage = StorageUtils.getOAuthStorage(StorageLayer.getStorage( this.appIdentifier.getAsPublicTenantIdentifier(), main)); - result.addProperty("totalNumberOfClients", oAuthStorage.countTotalNumberOfClientsForApp(appIdentifier)); - result.addProperty("numberOfClientCredentialsOnlyClients", oAuthStorage.countTotalNumberOfClientCredentialsOnlyClientsForApp(appIdentifier)); - result.addProperty("numberOfM2MTokensAlive", oAuthStorage.countTotalNumberOfM2MTokensAlive(appIdentifier)); + result.addProperty("totalNumberOfClients", oAuthStorage.countTotalNumberOfOAuthClients(appIdentifier)); + result.addProperty("numberOfClientCredentialsOnlyClients", oAuthStorage.countTotalNumberOfClientCredentialsOnlyOAuthClients(appIdentifier)); + result.addProperty("numberOfM2MTokensAlive", oAuthStorage.countTotalNumberOfOAuthM2MTokensAlive(appIdentifier)); long now = System.currentTimeMillis(); JsonArray tokensCreatedArray = new JsonArray(); for (int i = 1; i <= 31; i++) { long timestamp = now - (i * 24 * 60 * 60 * 1000L); - int numberOfTokensCreated = oAuthStorage.countTotalNumberOfM2MTokensCreatedSince(this.appIdentifier, timestamp); + int numberOfTokensCreated = oAuthStorage.countTotalNumberOfOAuthM2MTokensCreatedSince(this.appIdentifier, timestamp); tokensCreatedArray.add(new JsonPrimitive(numberOfTokensCreated)); } result.add("numberOfM2MTokensCreated", tokensCreatedArray); diff --git a/src/main/java/io/supertokens/cronjobs/cleanupOAuthRevokeListAndChallenges/CleanupOAuthRevokeListAndChallenges.java b/src/main/java/io/supertokens/cronjobs/cleanupOAuthRevokeListAndChallenges/CleanupOAuthRevokeListAndChallenges.java index b94370839..f61a68a77 100644 --- a/src/main/java/io/supertokens/cronjobs/cleanupOAuthRevokeListAndChallenges/CleanupOAuthRevokeListAndChallenges.java +++ b/src/main/java/io/supertokens/cronjobs/cleanupOAuthRevokeListAndChallenges/CleanupOAuthRevokeListAndChallenges.java @@ -28,11 +28,10 @@ public static CleanupOAuthRevokeListAndChallenges init(Main main, List listClientsForApp(AppIdentifier appIdentifier) throws StorageQueryException { + public List listOAuthClients(AppIdentifier appIdentifier) throws StorageQueryException { try { - return OAuthQueries.listClientsForApp(this, appIdentifier); + return OAuthQueries.listOAuthClients(this, appIdentifier); } catch (SQLException e) { throw new StorageQueryException(e); } } @Override - public void revoke(AppIdentifier appIdentifier, String targetType, String targetValue, long exp) + public void revokeOAuthTokensBasedOnTargetFields(AppIdentifier appIdentifier, OAuthRevokeTargetType targetType, String targetValue, long exp) throws StorageQueryException { try { - OAuthQueries.revoke(this, appIdentifier, targetType, targetValue, exp); + OAuthQueries.revokeOAuthTokensBasedOnTargetFields(this, appIdentifier, targetType, targetValue, exp); } catch (SQLException e) { throw new StorageQueryException(e); } @@ -3060,31 +3061,40 @@ public void revoke(AppIdentifier appIdentifier, String targetType, String target } @Override - public boolean isRevoked(AppIdentifier appIdentifier, String[] targetTypes, String[] targetValues, long issuedAt) + public boolean isOAuthTokenRevokedBasedOnTargetFields(AppIdentifier appIdentifier, OAuthRevokeTargetType[] targetTypes, String[] targetValues, long issuedAt) throws StorageQueryException { try { - return OAuthQueries.isRevoked(this, appIdentifier, targetTypes, targetValues, issuedAt); + return OAuthQueries.isOAuthTokenRevokedBasedOnTargetFields(this, appIdentifier, targetTypes, targetValues, issuedAt); } catch (SQLException e) { throw new StorageQueryException(e); } } @Override - public void addM2MToken(AppIdentifier appIdentifier, String clientId, long iat, long exp) + public void addOAuthM2MTokenForStats(AppIdentifier appIdentifier, String clientId, long iat, long exp) throws StorageQueryException { try { - OAuthQueries.addM2MToken(this, appIdentifier, clientId, iat, exp); + OAuthQueries.addOAuthM2MTokenForStats(this, appIdentifier, clientId, iat, exp); } catch (SQLException e) { throw new StorageQueryException(e); } } @Override - public void addLogoutChallenge(AppIdentifier appIdentifier, String challenge, String clientId, + public void cleanUpExpiredAndRevokedOAuthTokensList() throws StorageQueryException { + try { + OAuthQueries.cleanUpExpiredAndRevokedOAuthTokensList(this); + } catch (SQLException e) { + throw new StorageQueryException(e); + } + } + + @Override + public void addOAuthLogoutChallenge(AppIdentifier appIdentifier, String challenge, String clientId, String postLogoutRedirectionUri, String sessionHandle, String state, long timeCreated) throws StorageQueryException, DuplicateOAuthLogoutChallengeException { try { - OAuthQueries.addLogoutChallenge(this, appIdentifier, challenge, clientId, postLogoutRedirectionUri, sessionHandle, state, timeCreated); + OAuthQueries.addOAuthLogoutChallenge(this, appIdentifier, challenge, clientId, postLogoutRedirectionUri, sessionHandle, state, timeCreated); } catch (SQLException e) { SQLiteConfig config = Config.getConfig(this); String serverMessage = e.getMessage(); @@ -3098,74 +3108,65 @@ public void addLogoutChallenge(AppIdentifier appIdentifier, String challenge, St } @Override - public OAuthLogoutChallenge getLogoutChallenge(AppIdentifier appIdentifier, String challenge) throws StorageQueryException { + public OAuthLogoutChallenge getOAuthLogoutChallenge(AppIdentifier appIdentifier, String challenge) throws StorageQueryException { try { - return OAuthQueries.getLogoutChallenge(this, appIdentifier, challenge); + return OAuthQueries.getOAuthLogoutChallenge(this, appIdentifier, challenge); } catch (SQLException e) { throw new StorageQueryException(e); } } @Override - public void deleteLogoutChallenge(AppIdentifier appIdentifier, String challenge) throws StorageQueryException { + public void deleteOAuthLogoutChallenge(AppIdentifier appIdentifier, String challenge) throws StorageQueryException { try { - OAuthQueries.deleteLogoutChallenge(this, appIdentifier, challenge); + OAuthQueries.deleteOAuthLogoutChallenge(this, appIdentifier, challenge); } catch (SQLException e) { throw new StorageQueryException(e); } } @Override - public void deleteLogoutChallengesBefore(AppIdentifier appIdentifier, long time) throws StorageQueryException { + public void deleteOAuthLogoutChallengesBefore(long time) throws StorageQueryException { try { - OAuthQueries.deleteLogoutChallengesBefore(this, appIdentifier, time); + OAuthQueries.deleteOAuthLogoutChallengesBefore(this, time); } catch (SQLException e) { throw new StorageQueryException(e); } } @Override - public void cleanUpExpiredAndRevokedTokens(AppIdentifier appIdentifier) throws StorageQueryException { + public int countTotalNumberOfOAuthClients(AppIdentifier appIdentifier) throws StorageQueryException { try { - OAuthQueries.cleanUpExpiredAndRevokedTokens(this, appIdentifier); + return OAuthQueries.countTotalNumberOfClients(this, appIdentifier, false); } catch (SQLException e) { throw new StorageQueryException(e); } } @Override - public int countTotalNumberOfClientCredentialsOnlyClientsForApp(AppIdentifier appIdentifier) + public int countTotalNumberOfClientCredentialsOnlyOAuthClients(AppIdentifier appIdentifier) throws StorageQueryException { try { - return OAuthQueries.countTotalNumberOfClientsForApp(this, appIdentifier, true); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public int countTotalNumberOfClientsForApp(AppIdentifier appIdentifier) throws StorageQueryException { - try { - return OAuthQueries.countTotalNumberOfClientsForApp(this, appIdentifier, false); + return OAuthQueries.countTotalNumberOfClients(this, appIdentifier, true); } catch (SQLException e) { throw new StorageQueryException(e); } } @Override - public int countTotalNumberOfM2MTokensAlive(AppIdentifier appIdentifier) throws StorageQueryException { + public int countTotalNumberOfOAuthM2MTokensCreatedSince(AppIdentifier appIdentifier, long since) + throws StorageQueryException { try { - return OAuthQueries.countTotalNumberOfM2MTokensAlive(this, appIdentifier); + return OAuthQueries.countTotalNumberOfOAuthM2MTokensCreatedSince(this, appIdentifier, since); } catch (SQLException e) { throw new StorageQueryException(e); } } @Override - public int countTotalNumberOfM2MTokensCreatedSince(AppIdentifier appIdentifier, long since) - throws StorageQueryException { + public int countTotalNumberOfOAuthM2MTokensAlive(AppIdentifier appIdentifier) throws StorageQueryException { try { - return OAuthQueries.countTotalNumberOfM2MTokensCreatedSince(this, appIdentifier, since); + return OAuthQueries.countTotalNumberOfOAuthM2MTokensAlive(this, appIdentifier); } catch (SQLException e) { throw new StorageQueryException(e); } diff --git a/src/main/java/io/supertokens/inmemorydb/queries/OAuthQueries.java b/src/main/java/io/supertokens/inmemorydb/queries/OAuthQueries.java index 9fa6e3d46..e87103662 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/OAuthQueries.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/OAuthQueries.java @@ -21,6 +21,7 @@ import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.oauth.OAuthLogoutChallenge; +import io.supertokens.pluginInterface.oauth.OAuthRevokeTargetType; import java.sql.ResultSet; import java.sql.SQLException; @@ -119,7 +120,7 @@ public static String getQueryToCreateOAuthLogoutChallengesTimeCreatedIndex(Start + oAuth2LogoutChallengesTable + "(time_created ASC, app_id ASC);"; } - public static boolean isClientIdForAppId(Start start, String clientId, AppIdentifier appIdentifier) + public static boolean doesOAuthClientIdExist(Start start, String clientId, AppIdentifier appIdentifier) throws SQLException, StorageQueryException { String QUERY = "SELECT app_id FROM " + Config.getConfig(start).getOAuthClientsTable() + " WHERE client_id = ? AND app_id = ?"; @@ -130,7 +131,7 @@ public static boolean isClientIdForAppId(Start start, String clientId, AppIdenti }, ResultSet::next); } - public static List listClientsForApp(Start start, AppIdentifier appIdentifier) + public static List listOAuthClients(Start start, AppIdentifier appIdentifier) throws SQLException, StorageQueryException { String QUERY = "SELECT client_id FROM " + Config.getConfig(start).getOAuthClientsTable() + " WHERE app_id = ?"; @@ -145,7 +146,7 @@ public static List listClientsForApp(Start start, AppIdentifier appIdent }); } - public static void insertOrUpdateClient(Start start, AppIdentifier appIdentifier, String clientId, + public static void addOrUpdateOauthClient(Start start, AppIdentifier appIdentifier, String clientId, boolean isClientCredentialsOnly) throws SQLException, StorageQueryException { String INSERT = "INSERT INTO " + Config.getConfig(start).getOAuthClientsTable() @@ -159,7 +160,7 @@ public static void insertOrUpdateClient(Start start, AppIdentifier appIdentifier }); } - public static boolean deleteClient(Start start, String clientId, AppIdentifier appIdentifier) + public static boolean deleteOAuthClient(Start start, String clientId, AppIdentifier appIdentifier) throws SQLException, StorageQueryException { String DELETE = "DELETE FROM " + Config.getConfig(start).getOAuthClientsTable() + " WHERE app_id = ? AND client_id = ?"; @@ -170,7 +171,7 @@ public static boolean deleteClient(Start start, String clientId, AppIdentifier a return numberOfRow > 0; } - public static void revoke(Start start, AppIdentifier appIdentifier, String targetType, String targetValue, long exp) + public static void revokeOAuthTokensBasedOnTargetFields(Start start, AppIdentifier appIdentifier, OAuthRevokeTargetType targetType, String targetValue, long exp) throws SQLException, StorageQueryException { String INSERT = "INSERT INTO " + Config.getConfig(start).getOAuthRevokeTable() + "(app_id, target_type, target_value, timestamp, exp) VALUES (?, ?, ?, ?, ?) " @@ -179,7 +180,7 @@ public static void revoke(Start start, AppIdentifier appIdentifier, String targe long currentTime = System.currentTimeMillis() / 1000; update(start, INSERT, pst -> { pst.setString(1, appIdentifier.getAppId()); - pst.setString(2, targetType); + pst.setString(2, targetType.getValue()); pst.setString(3, targetValue); pst.setLong(4, currentTime); pst.setLong(5, exp); @@ -188,7 +189,7 @@ public static void revoke(Start start, AppIdentifier appIdentifier, String targe }); } - public static boolean isRevoked(Start start, AppIdentifier appIdentifier, String[] targetTypes, String[] targetValues, long issuedAt) + public static boolean isOAuthTokenRevokedBasedOnTargetFields(Start start, AppIdentifier appIdentifier, OAuthRevokeTargetType[] targetTypes, String[] targetValues, long issuedAt) throws SQLException, StorageQueryException { String QUERY = "SELECT app_id FROM " + Config.getConfig(start).getOAuthRevokeTable() + " WHERE app_id = ? AND timestamp >= ? AND ("; @@ -209,7 +210,7 @@ public static boolean isRevoked(Start start, AppIdentifier appIdentifier, String int index = 3; for (int i = 0; i < targetTypes.length; i++) { - pst.setString(index, targetTypes[i]); + pst.setString(index, targetTypes[i].getValue()); index++; pst.setString(index, targetValues[i]); index++; @@ -217,7 +218,7 @@ public static boolean isRevoked(Start start, AppIdentifier appIdentifier, String }, ResultSet::next); } - public static int countTotalNumberOfClientsForApp(Start start, AppIdentifier appIdentifier, + public static int countTotalNumberOfClients(Start start, AppIdentifier appIdentifier, boolean filterByClientCredentialsOnly) throws SQLException, StorageQueryException { if (filterByClientCredentialsOnly) { String QUERY = "SELECT COUNT(*) as c FROM " + Config.getConfig(start).getOAuthClientsTable() + @@ -245,7 +246,7 @@ public static int countTotalNumberOfClientsForApp(Start start, AppIdentifier app } } - public static int countTotalNumberOfM2MTokensAlive(Start start, AppIdentifier appIdentifier) + public static int countTotalNumberOfOAuthM2MTokensAlive(Start start, AppIdentifier appIdentifier) throws SQLException, StorageQueryException { String QUERY = "SELECT COUNT(*) as c FROM " + Config.getConfig(start).getOAuthM2MTokensTable() + " WHERE app_id = ? AND exp > ?"; @@ -260,7 +261,7 @@ public static int countTotalNumberOfM2MTokensAlive(Start start, AppIdentifier ap }); } - public static int countTotalNumberOfM2MTokensCreatedSince(Start start, AppIdentifier appIdentifier, long since) + public static int countTotalNumberOfOAuthM2MTokensCreatedSince(Start start, AppIdentifier appIdentifier, long since) throws SQLException, StorageQueryException { String QUERY = "SELECT COUNT(*) as c FROM " + Config.getConfig(start).getOAuthM2MTokensTable() + " WHERE app_id = ? AND iat >= ?"; @@ -275,7 +276,7 @@ public static int countTotalNumberOfM2MTokensCreatedSince(Start start, AppIdenti }); } - public static void addM2MToken(Start start, AppIdentifier appIdentifier, String clientId, long iat, long exp) + public static void addOAuthM2MTokenForStats(Start start, AppIdentifier appIdentifier, String clientId, long iat, long exp) throws SQLException, StorageQueryException { String QUERY = "INSERT INTO " + Config.getConfig(start).getOAuthM2MTokensTable() + " (app_id, client_id, iat, exp) VALUES (?, ?, ?, ?)"; @@ -287,33 +288,31 @@ public static void addM2MToken(Start start, AppIdentifier appIdentifier, String }); } - public static void cleanUpExpiredAndRevokedTokens(Start start, AppIdentifier appIdentifier) throws SQLException, StorageQueryException { + public static void cleanUpExpiredAndRevokedOAuthTokensList(Start start) throws SQLException, StorageQueryException { { // delete expired M2M tokens String QUERY = "DELETE FROM " + Config.getConfig(start).getOAuthM2MTokensTable() + - " WHERE app_id = ? AND exp < ?"; + " WHERE exp < ?"; long timestamp = System.currentTimeMillis() / 1000 - 3600 * 24 * 31; // expired 31 days ago update(start, QUERY, pst -> { - pst.setString(1, appIdentifier.getAppId()); - pst.setLong(2, timestamp); + pst.setLong(1, timestamp); }); } { // delete expired revoked tokens String QUERY = "DELETE FROM " + Config.getConfig(start).getOAuthRevokeTable() + - " WHERE app_id = ? AND exp < ?"; + " WHERE exp < ?"; long timestamp = System.currentTimeMillis() / 1000 - 3600 * 24 * 31; // expired 31 days ago update(start, QUERY, pst -> { - pst.setString(1, appIdentifier.getAppId()); - pst.setLong(2, timestamp); + pst.setLong(1, timestamp); }); } } - public static void addLogoutChallenge(Start start, AppIdentifier appIdentifier, String challenge, String clientId, + public static void addOAuthLogoutChallenge(Start start, AppIdentifier appIdentifier, String challenge, String clientId, String postLogoutRedirectionUri, String sessionHandle, String state, long timeCreated) throws SQLException, StorageQueryException { String QUERY = "INSERT INTO " + Config.getConfig(start).getOAuthLogoutChallengesTable() + " (app_id, challenge, client_id, post_logout_redirect_uri, session_handle, state, time_created) VALUES (?, ?, ?, ?, ?, ?, ?)"; @@ -328,7 +327,7 @@ public static void addLogoutChallenge(Start start, AppIdentifier appIdentifier, }); } - public static OAuthLogoutChallenge getLogoutChallenge(Start start, AppIdentifier appIdentifier, String challenge) throws SQLException, StorageQueryException { + public static OAuthLogoutChallenge getOAuthLogoutChallenge(Start start, AppIdentifier appIdentifier, String challenge) throws SQLException, StorageQueryException { String QUERY = "SELECT challenge, client_id, post_logout_redirect_uri, session_handle, state, time_created FROM " + Config.getConfig(start).getOAuthLogoutChallengesTable() + " WHERE app_id = ? AND challenge = ?"; @@ -351,7 +350,7 @@ public static OAuthLogoutChallenge getLogoutChallenge(Start start, AppIdentifier }); } - public static void deleteLogoutChallenge(Start start, AppIdentifier appIdentifier, String challenge) throws SQLException, StorageQueryException { + public static void deleteOAuthLogoutChallenge(Start start, AppIdentifier appIdentifier, String challenge) throws SQLException, StorageQueryException { String QUERY = "DELETE FROM " + Config.getConfig(start).getOAuthLogoutChallengesTable() + " WHERE app_id = ? AND challenge = ?"; update(start, QUERY, pst -> { @@ -360,12 +359,11 @@ public static void deleteLogoutChallenge(Start start, AppIdentifier appIdentifie }); } - public static void deleteLogoutChallengesBefore(Start start, AppIdentifier appIdentifier, long time) throws SQLException, StorageQueryException { + public static void deleteOAuthLogoutChallengesBefore(Start start, long time) throws SQLException, StorageQueryException { String QUERY = "DELETE FROM " + Config.getConfig(start).getOAuthLogoutChallengesTable() + - " WHERE app_id = ? AND time_created < ?"; + " WHERE time_created < ?"; update(start, QUERY, pst -> { - pst.setString(1, appIdentifier.getAppId()); - pst.setLong(2, time); + pst.setLong(1, time); }); } } diff --git a/src/main/java/io/supertokens/oauth/OAuth.java b/src/main/java/io/supertokens/oauth/OAuth.java index b58a98318..6da1f452a 100644 --- a/src/main/java/io/supertokens/oauth/OAuth.java +++ b/src/main/java/io/supertokens/oauth/OAuth.java @@ -37,6 +37,7 @@ import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.oauth.OAuthLogoutChallenge; +import io.supertokens.pluginInterface.oauth.OAuthRevokeTargetType; import io.supertokens.pluginInterface.oauth.OAuthStorage; import io.supertokens.pluginInterface.oauth.exception.DuplicateOAuthLogoutChallengeException; import io.supertokens.session.jwt.JWT.JWTException; @@ -75,7 +76,7 @@ public static HttpRequestForOry.Response doOAuthProxyGET(Main main, AppIdentifie } if (clientIdToCheck != null) { - if (!oauthStorage.doesClientIdExistForApp(appIdentifier, clientIdToCheck)) { + if (!oauthStorage.doesOAuthClientIdExist(appIdentifier, clientIdToCheck)) { throw new OAuthClientNotFoundException(); } } @@ -116,7 +117,7 @@ public static HttpRequestForOry.Response doOAuthProxyFormPOST(Main main, AppIden } if (clientIdToCheck != null) { - if (!oauthStorage.doesClientIdExistForApp(appIdentifier, clientIdToCheck)) { + if (!oauthStorage.doesOAuthClientIdExist(appIdentifier, clientIdToCheck)) { throw new OAuthClientNotFoundException(); } } @@ -157,7 +158,7 @@ public static HttpRequestForOry.Response doOAuthProxyJsonPOST(Main main, AppIden } if (clientIdToCheck != null) { - if (!oauthStorage.doesClientIdExistForApp(appIdentifier, clientIdToCheck)) { + if (!oauthStorage.doesOAuthClientIdExist(appIdentifier, clientIdToCheck)) { throw new OAuthClientNotFoundException(); } } @@ -199,7 +200,7 @@ public static HttpRequestForOry.Response doOAuthProxyJsonPUT(Main main, AppIdent } if (clientIdToCheck != null) { - if (!oauthStorage.doesClientIdExistForApp(appIdentifier, clientIdToCheck)) { + if (!oauthStorage.doesOAuthClientIdExist(appIdentifier, clientIdToCheck)) { throw new OAuthClientNotFoundException(); } } @@ -240,7 +241,7 @@ public static HttpRequestForOry.Response doOAuthProxyJsonDELETE(Main main, AppId } if (clientIdToCheck != null) { - if (!oauthStorage.doesClientIdExistForApp(appIdentifier, clientIdToCheck)) { + if (!oauthStorage.doesOAuthClientIdExist(appIdentifier, clientIdToCheck)) { throw new OAuthClientNotFoundException(); } } @@ -368,17 +369,17 @@ public static JsonObject transformTokens(Main main, AppIdentifier appIdentifier, public static void addOrUpdateClientId(Main main, AppIdentifier appIdentifier, Storage storage, String clientId, boolean isClientCredentialsOnly) throws StorageQueryException { OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage); - oauthStorage.addOrUpdateClientForApp(appIdentifier, clientId, isClientCredentialsOnly); + oauthStorage.addOrUpdateOauthClient(appIdentifier, clientId, isClientCredentialsOnly); } public static void removeClientId(Main main, AppIdentifier appIdentifier, Storage storage, String clientId) throws StorageQueryException { OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage); - oauthStorage.removeAppClientAssociation(appIdentifier, clientId); + oauthStorage.deleteOAuthClient(appIdentifier, clientId); } public static List listClientIds(Main main, AppIdentifier appIdentifier, Storage storage) throws StorageQueryException { OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage); - return oauthStorage.listClientsForApp(appIdentifier); + return oauthStorage.listOAuthClients(appIdentifier); } private static Map convertCamelToSnakeCase(Map queryParams) { @@ -466,28 +467,28 @@ public static void verifyAndUpdateIntrospectRefreshTokenPayload(Main main, AppId private static boolean isTokenRevokedBasedOnPayload(OAuthStorage oauthStorage, AppIdentifier appIdentifier, JsonObject payload) throws StorageQueryException { long issuedAt = payload.get("iat").getAsLong(); - List targetTypes = new ArrayList<>(); + List targetTypes = new ArrayList<>(); List targetValues = new ArrayList<>(); - targetTypes.add("client_id"); + targetTypes.add(OAuthRevokeTargetType.CLIENT_ID); targetValues.add(payload.get("client_id").getAsString()); if (payload.has("jti")) { - targetTypes.add("jti"); + targetTypes.add(OAuthRevokeTargetType.JTI); targetValues.add(payload.get("jti").getAsString()); } if (payload.has("gid")) { - targetTypes.add("gid"); + targetTypes.add(OAuthRevokeTargetType.GID); targetValues.add(payload.get("gid").getAsString()); } if (payload.has("sessionHandle")) { - targetTypes.add("session_handle"); + targetTypes.add(OAuthRevokeTargetType.SESSION_HANDLE); targetValues.add(payload.get("sessionHandle").getAsString()); } - return oauthStorage.isRevoked(appIdentifier, targetTypes.toArray(new String[0]), targetValues.toArray(new String[0]), issuedAt); + return oauthStorage.isOAuthTokenRevokedBasedOnTargetFields(appIdentifier, targetTypes.toArray(new OAuthRevokeTargetType[0]), targetValues.toArray(new String[0]), issuedAt); } public static JsonObject introspectAccessToken(Main main, AppIdentifier appIdentifier, Storage storage, @@ -522,12 +523,12 @@ public static JsonObject introspectAccessToken(Main main, AppIdentifier appIdent public static void revokeTokensForClientId(Main main, AppIdentifier appIdentifier, Storage storage, String clientId) throws StorageQueryException { long exp = System.currentTimeMillis() / 1000 + 3600 * 24 * 183; // 6 month from now OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage); - oauthStorage.revoke(appIdentifier, "client_id", clientId, exp); + oauthStorage.revokeOAuthTokensBasedOnTargetFields(appIdentifier, OAuthRevokeTargetType.CLIENT_ID, clientId, exp); } public static void revokeRefreshToken(Main main, AppIdentifier appIdentifier, Storage storage, String gid, long exp) throws StorageQueryException, NoSuchAlgorithmException { OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage); - oauthStorage.revoke(appIdentifier, "gid", gid, exp); + oauthStorage.revokeOAuthTokensBasedOnTargetFields(appIdentifier, OAuthRevokeTargetType.GID, gid, exp); } public static void revokeAccessToken(Main main, AppIdentifier appIdentifier, @@ -540,7 +541,7 @@ public static void revokeAccessToken(Main main, AppIdentifier appIdentifier, if (payload.has("stt") && payload.get("stt").getAsInt() == OAuthToken.TokenType.ACCESS_TOKEN.getValue()) { String jti = payload.get("jti").getAsString(); - oauthStorage.revoke(appIdentifier, "jti", jti, exp); + oauthStorage.revokeOAuthTokensBasedOnTargetFields(appIdentifier, OAuthRevokeTargetType.JTI, jti, exp); } } catch (TryRefreshTokenException e) { @@ -552,7 +553,7 @@ public static void revokeSessionHandle(Main main, AppIdentifier appIdentifier, S String sessionHandle) throws StorageQueryException { long exp = System.currentTimeMillis() / 1000 + 3600 * 24 * 183; // 6 month from now OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage); - oauthStorage.revoke(appIdentifier, "session_handle", sessionHandle, exp); + oauthStorage.revokeOAuthTokensBasedOnTargetFields(appIdentifier, OAuthRevokeTargetType.SESSION_HANDLE, sessionHandle, exp); } public static JsonObject verifyIdTokenAndGetPayload(Main main, AppIdentifier appIdentifier, Storage storage, @@ -568,7 +569,7 @@ public static JsonObject verifyIdTokenAndGetPayload(Main main, AppIdentifier app public static void addM2MToken(Main main, AppIdentifier appIdentifier, Storage storage, String accessToken) throws StorageQueryException, TenantOrAppNotFoundException, TryRefreshTokenException, UnsupportedJWTSigningAlgorithmException, StorageTransactionLogicException { OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage); JsonObject payload = OAuthToken.getPayloadFromJWTToken(appIdentifier, main, accessToken); - oauthStorage.addM2MToken(appIdentifier, payload.get("client_id").getAsString(), payload.get("iat").getAsLong(), payload.get("exp").getAsLong()); + oauthStorage.addOAuthM2MTokenForStats(appIdentifier, payload.get("client_id").getAsString(), payload.get("iat").getAsLong(), payload.get("exp").getAsLong()); } public static String createLogoutRequestAndReturnRedirectUri(Main main, AppIdentifier appIdentifier, Storage storage, String clientId, @@ -579,7 +580,7 @@ public static String createLogoutRequestAndReturnRedirectUri(Main main, AppIdent while (true) { try { String logoutChallenge = UUID.randomUUID().toString(); - oauthStorage.addLogoutChallenge(appIdentifier, logoutChallenge, clientId, postLogoutRedirectionUri, sessionHandle, state, System.currentTimeMillis()); + oauthStorage.addOAuthLogoutChallenge(appIdentifier, logoutChallenge, clientId, postLogoutRedirectionUri, sessionHandle, state, System.currentTimeMillis()); return "{apiDomain}/oauth/logout?logout_challenge=" + logoutChallenge; } catch (DuplicateOAuthLogoutChallengeException e) { @@ -590,7 +591,7 @@ public static String createLogoutRequestAndReturnRedirectUri(Main main, AppIdent public static String consumeLogoutChallengeAndGetRedirectUri(Main main, AppIdentifier appIdentifier, Storage storage, String challenge) throws StorageQueryException, OAuthAPIException { OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage); - OAuthLogoutChallenge logoutChallenge = oauthStorage.getLogoutChallenge(appIdentifier, challenge); + OAuthLogoutChallenge logoutChallenge = oauthStorage.getOAuthLogoutChallenge(appIdentifier, challenge); if (logoutChallenge == null) { throw new OAuthAPIException("invalid_request", "Logout request not found", 400); @@ -612,6 +613,6 @@ public static String consumeLogoutChallengeAndGetRedirectUri(Main main, AppIdent public static void deleteLogoutChallenge(Main main, AppIdentifier appIdentifier, Storage storage, String challenge) throws StorageQueryException { OAuthStorage oauthStorage = StorageUtils.getOAuthStorage(storage); - oauthStorage.deleteLogoutChallenge(appIdentifier, challenge); + oauthStorage.deleteOAuthLogoutChallenge(appIdentifier, challenge); } } diff --git a/src/test/java/io/supertokens/test/multitenant/TestAppData.java b/src/test/java/io/supertokens/test/multitenant/TestAppData.java index 24a51e436..71d895b5d 100644 --- a/src/test/java/io/supertokens/test/multitenant/TestAppData.java +++ b/src/test/java/io/supertokens/test/multitenant/TestAppData.java @@ -179,7 +179,7 @@ null, null, new JsonObject() OAuth.addOrUpdateClientId(process.getProcess(), app.toAppIdentifier(), appStorage, "test", false); OAuth.createLogoutRequestAndReturnRedirectUri(process.getProcess(), app.toAppIdentifier(), appStorage, "test", "http://localhost", "sessionHandle", "state"); - ((OAuthStorage) appStorage).addM2MToken(app.toAppIdentifier(), "test", 1000, 2000); + ((OAuthStorage) appStorage).addOAuthM2MTokenForStats(app.toAppIdentifier(), "test", 1000, 2000); OAuth.revokeSessionHandle(process.getProcess(), app.toAppIdentifier(), appStorage, "sessionHandle"); String[] tablesThatHaveData = appStorage