Skip to content

Commit 30642ca

Browse files
authored
fix: backports to core 7.0 (#213)
1 parent 969b945 commit 30642ca

File tree

6 files changed

+37
-20
lines changed

6 files changed

+37
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
## [5.0.9] - 2024-03-21
11+
12+
- Fixes user id mapping queries
13+
- Adds a new `useStaticKey` param to `updateSessionInfo_Transaction`
14+
- This enables smooth switching between `useDynamicAccessTokenSigningKey` settings by allowing refresh calls to
15+
change the signing key type of a session
16+
1017
## [5.0.8] - 2024-02-19
1118

1219
- Fixes vulnerabilities in dependencies

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'java-library'
33
}
44

5-
version = "5.0.8"
5+
version = "5.0.9"
66

77
repositories {
88
mavenCentral()

src/main/java/io/supertokens/storage/postgresql/Start.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,11 @@ public SessionInfo getSessionInfo_Transaction(TenantIdentifier tenantIdentifier,
649649
@Override
650650
public void updateSessionInfo_Transaction(TenantIdentifier tenantIdentifier, TransactionConnection con,
651651
String sessionHandle, String refreshTokenHash2,
652-
long expiry) throws StorageQueryException {
652+
long expiry, boolean useStaticKey) throws StorageQueryException {
653653
Connection sqlCon = (Connection) con.getConnection();
654654
try {
655655
SessionQueries.updateSessionInfo_Transaction(this, sqlCon, tenantIdentifier, sessionHandle,
656-
refreshTokenHash2, expiry);
656+
refreshTokenHash2, expiry, useStaticKey);
657657
} catch (SQLException e) {
658658
throw new StorageQueryException(e);
659659
}
@@ -2244,10 +2244,11 @@ public boolean updateOrDeleteExternalUserIdInfo(AppIdentifier appIdentifier, Str
22442244
}
22452245

22462246
@Override
2247-
public HashMap<String, String> getUserIdMappingForSuperTokensIds(ArrayList<String> userIds)
2247+
public HashMap<String, String> getUserIdMappingForSuperTokensIds(AppIdentifier appIdentifier,
2248+
ArrayList<String> userIds)
22482249
throws StorageQueryException {
22492250
try {
2250-
return UserIdMappingQueries.getUserIdMappingWithUserIds(this, userIds);
2251+
return UserIdMappingQueries.getUserIdMappingWithUserIds(this, appIdentifier, userIds);
22512252
} catch (SQLException e) {
22522253
throw new StorageQueryException(e);
22532254
}

src/main/java/io/supertokens/storage/postgresql/queries/EmailVerificationQueries.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public static List<String> isEmailVerified_transaction(Start start, Connection s
271271
// calculating the verified emails
272272

273273
HashMap<String, String> supertokensUserIdToExternalUserIdMap = UserIdMappingQueries.getUserIdMappingWithUserIds_Transaction(start,
274-
sqlCon, supertokensUserIds);
274+
sqlCon, appIdentifier, supertokensUserIds);
275275
HashMap<String, String> externalUserIdToSupertokensUserIdMap = new HashMap<>();
276276

277277
List<String> supertokensOrExternalUserIdsToQuery = new ArrayList<>();
@@ -340,7 +340,7 @@ public static List<String> isEmailVerified(Start start, AppIdentifier appIdentif
340340
// We have external user id stored in the email verification table, so we need to fetch the mapped userids for
341341
// calculating the verified emails
342342
HashMap<String, String> supertokensUserIdToExternalUserIdMap = UserIdMappingQueries.getUserIdMappingWithUserIds(start,
343-
supertokensUserIds);
343+
appIdentifier, supertokensUserIds);
344344
HashMap<String, String> externalUserIdToSupertokensUserIdMap = new HashMap<>();
345345
List<String> supertokensOrExternalUserIdsToQuery = new ArrayList<>();
346346
for (String userId : supertokensUserIds) {

src/main/java/io/supertokens/storage/postgresql/queries/SessionQueries.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,19 @@ public static SessionInfo getSessionInfo_Transaction(Start start, Connection con
166166

167167
public static void updateSessionInfo_Transaction(Start start, Connection con, TenantIdentifier tenantIdentifier,
168168
String sessionHandle,
169-
String refreshTokenHash2, long expiry)
169+
String refreshTokenHash2, long expiry, boolean useStaticKey)
170170
throws SQLException, StorageQueryException {
171171
String QUERY = "UPDATE " + getConfig(start).getSessionInfoTable()
172-
+ " SET refresh_token_hash_2 = ?, expires_at = ?"
172+
+ " SET refresh_token_hash_2 = ?, expires_at = ?, use_static_key = ?"
173173
+ " WHERE app_id = ? AND tenant_id = ? AND session_handle = ?";
174174

175175
update(con, QUERY, pst -> {
176176
pst.setString(1, refreshTokenHash2);
177177
pst.setLong(2, expiry);
178-
pst.setString(3, tenantIdentifier.getAppId());
179-
pst.setString(4, tenantIdentifier.getTenantId());
180-
pst.setString(5, sessionHandle);
178+
pst.setBoolean(3, useStaticKey);
179+
pst.setString(4, tenantIdentifier.getAppId());
180+
pst.setString(5, tenantIdentifier.getTenantId());
181+
pst.setString(6, sessionHandle);
181182
});
182183
}
183184

src/main/java/io/supertokens/storage/postgresql/queries/UserIdMappingQueries.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ public static UserIdMapping[] getUserIdMappingWithEitherSuperTokensUserIdOrExter
128128

129129
}
130130

131-
public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, List<String> userIds)
131+
public static HashMap<String, String> getUserIdMappingWithUserIds(Start start,
132+
AppIdentifier appIdentifier,
133+
List<String> userIds)
132134
throws SQLException, StorageQueryException {
133135

134136
if (userIds.size() == 0) {
@@ -137,7 +139,8 @@ public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, L
137139

138140
// No need to filter based on tenantId because the id list is already filtered for a tenant
139141
StringBuilder QUERY = new StringBuilder(
140-
"SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable() + " WHERE supertokens_user_id IN (");
142+
"SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable() + " WHERE app_id = ? AND " +
143+
"supertokens_user_id IN (");
141144
for (int i = 0; i < userIds.size(); i++) {
142145
QUERY.append("?");
143146
if (i != userIds.size() - 1) {
@@ -147,9 +150,10 @@ public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, L
147150
}
148151
QUERY.append(")");
149152
return execute(start, QUERY.toString(), pst -> {
153+
pst.setString(1, appIdentifier.getAppId());
150154
for (int i = 0; i < userIds.size(); i++) {
151-
// i+1 cause this starts with 1 and not 0
152-
pst.setString(i + 1, userIds.get(i));
155+
// i+2 cause this starts with 1 and not 0, 1 is appId
156+
pst.setString(i + 2, userIds.get(i));
153157
}
154158
}, result -> {
155159
HashMap<String, String> userIdMappings = new HashMap<>();
@@ -161,7 +165,9 @@ public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, L
161165
});
162166
}
163167

164-
public static HashMap<String, String> getUserIdMappingWithUserIds_Transaction(Start start, Connection sqlCon, List<String> userIds)
168+
public static HashMap<String, String> getUserIdMappingWithUserIds_Transaction(Start start, Connection sqlCon,
169+
AppIdentifier appIdentifier,
170+
List<String> userIds)
165171
throws SQLException, StorageQueryException {
166172

167173
if (userIds.size() == 0) {
@@ -170,7 +176,8 @@ public static HashMap<String, String> getUserIdMappingWithUserIds_Transaction(St
170176

171177
// No need to filter based on tenantId because the id list is already filtered for a tenant
172178
StringBuilder QUERY = new StringBuilder(
173-
"SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable() + " WHERE supertokens_user_id IN (");
179+
"SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable() + " WHERE " +
180+
"app_id = ? AND supertokens_user_id IN (");
174181
for (int i = 0; i < userIds.size(); i++) {
175182
QUERY.append("?");
176183
if (i != userIds.size() - 1) {
@@ -180,9 +187,10 @@ public static HashMap<String, String> getUserIdMappingWithUserIds_Transaction(St
180187
}
181188
QUERY.append(")");
182189
return execute(sqlCon, QUERY.toString(), pst -> {
190+
pst.setString(1, appIdentifier.getAppId());
183191
for (int i = 0; i < userIds.size(); i++) {
184-
// i+1 cause this starts with 1 and not 0
185-
pst.setString(i + 1, userIds.get(i));
192+
// i+2 cause this starts with 1 and not 0, 1 is appId
193+
pst.setString(i + 2, userIds.get(i));
186194
}
187195
}, result -> {
188196
HashMap<String, String> userIdMappings = new HashMap<>();

0 commit comments

Comments
 (0)