From eb3a1dc8b5a8ebeff8a1536130d07c8282256de9 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 19 Sep 2024 13:44:44 +0530 Subject: [PATCH] fix: pr comment --- .../supertokens/storage/postgresql/Start.java | 4 +-- .../postgresql/queries/OAuthQueries.java | 27 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/supertokens/storage/postgresql/Start.java b/src/main/java/io/supertokens/storage/postgresql/Start.java index b20783f5..edba8626 100644 --- a/src/main/java/io/supertokens/storage/postgresql/Start.java +++ b/src/main/java/io/supertokens/storage/postgresql/Start.java @@ -3141,10 +3141,10 @@ public void revoke(AppIdentifier appIdentifier, String targetType, String target } @Override - public boolean isRevoked(AppIdentifier appIdentifier, String targetType, String targetValue, long issuedAt) + public boolean isRevoked(AppIdentifier appIdentifier, String[] targetTypes, String[] targetValues, long issuedAt) throws StorageQueryException { try { - return OAuthQueries.isRevoked(this, appIdentifier, targetType, targetValue, issuedAt); + return OAuthQueries.isRevoked(this, appIdentifier, targetTypes, targetValues, issuedAt); } catch (SQLException e) { throw new StorageQueryException(e); } diff --git a/src/main/java/io/supertokens/storage/postgresql/queries/OAuthQueries.java b/src/main/java/io/supertokens/storage/postgresql/queries/OAuthQueries.java index 3a9a2b97..ac05367b 100644 --- a/src/main/java/io/supertokens/storage/postgresql/queries/OAuthQueries.java +++ b/src/main/java/io/supertokens/storage/postgresql/queries/OAuthQueries.java @@ -119,15 +119,32 @@ public static void revoke(Start start, AppIdentifier appIdentifier, String targe }); } - public static boolean isRevoked(Start start, AppIdentifier appIdentifier, String targetType, String targetValue, long issuedAt) + public static boolean isRevoked(Start start, AppIdentifier appIdentifier, String[] targetTypes, String[] targetValues, long issuedAt) throws SQLException, StorageQueryException { String QUERY = "SELECT app_id FROM " + Config.getConfig(start).getOAuthRevokeTable() + - " WHERE app_id = ? AND target_type = ? AND target_value = ? and timestamp > ?"; + " WHERE app_id = ? AND timestamp > ? AND ("; + + for (int i = 0; i < targetTypes.length; i++) { + QUERY += "(target_type = ? AND target_value = ?)"; + + if (i < targetTypes.length - 1) { + QUERY += " OR "; + } + } + + QUERY += ")"; + return execute(start, QUERY, pst -> { pst.setString(1, appIdentifier.getAppId()); - pst.setString(2, targetType); - pst.setString(3, targetValue); - pst.setLong(4, issuedAt); + pst.setLong(2, issuedAt); + + int index = 3; + for (int i = 0; i < targetTypes.length; i++) { + pst.setString(index, targetTypes[i]); + index++; + pst.setString(index, targetValues[i]); + index++; + } }, ResultSet::next); } }