Skip to content

Commit ffefe74

Browse files
authored
fix: backports to core 7.0 (#969)
1 parent b7fdaeb commit ffefe74

19 files changed

+658
-42
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
66
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [7.0.19] - 2024-03-21
9+
- Fixes userIdMapping queries
10+
- Fixes issue with session creation for users with userIdMapping and accounts linked
11+
- Fixes active users tracking while linking accounts
12+
- Adds a new required `useDynamicSigningKey` into the request body of `RefreshSessionAPI`
13+
- This enables smooth switching between `useDynamicAccessTokenSigningKey` settings by allowing refresh calls to
14+
change the signing key type of a session
15+
816
## [7.0.18] - 2024-02-19
917

1018
- Fixes vulnerabilities in dependencies

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" }
1919
// }
2020
//}
2121

22-
version = "7.0.18"
22+
version = "7.0.19"
2323

2424

2525
repositories {

src/main/java/io/supertokens/ActiveUsers.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package io.supertokens;
22

3+
import io.supertokens.pluginInterface.ActiveUsersStorage;
34
import io.supertokens.pluginInterface.authRecipe.sqlStorage.AuthRecipeSQLStorage;
45
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
56
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
67
import io.supertokens.pluginInterface.multitenancy.AppIdentifierWithStorage;
78
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
9+
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
810
import io.supertokens.storageLayer.StorageLayer;
911
import org.jetbrains.annotations.TestOnly;
1012

@@ -33,6 +35,19 @@ public static int countUsersActiveSince(AppIdentifierWithStorage appIdentifierWi
3335
return appIdentifierWithStorage.getActiveUsersStorage().countUsersActiveSince(appIdentifierWithStorage, time);
3436
}
3537

38+
public static void updateLastActiveAfterLinking(AppIdentifierWithStorage appIdentifierWithStorage,
39+
Main main, String primaryUserId, String recipeUserId)
40+
throws StorageQueryException, TenantOrAppNotFoundException, StorageTransactionLogicException {
41+
ActiveUsersStorage activeUsersStorage = appIdentifierWithStorage.getActiveUsersStorage();
42+
43+
((SQLStorage) activeUsersStorage).startTransaction(con -> {
44+
activeUsersStorage.deleteUserActive_Transaction(con, appIdentifierWithStorage, recipeUserId);
45+
return null;
46+
});
47+
48+
updateLastActive(appIdentifierWithStorage, main, primaryUserId);
49+
}
50+
3651
@TestOnly
3752
public static int countUsersActiveSince(Main main, long time)
3853
throws StorageQueryException, TenantOrAppNotFoundException {

src/main/java/io/supertokens/inmemorydb/Start.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,11 @@ public SessionInfo getSessionInfo_Transaction(TenantIdentifier tenantIdentifier,
520520
@Override
521521
public void updateSessionInfo_Transaction(TenantIdentifier tenantIdentifier, TransactionConnection con,
522522
String sessionHandle, String refreshTokenHash2,
523-
long expiry) throws StorageQueryException {
523+
long expiry, boolean useStaticKey) throws StorageQueryException {
524524
Connection sqlCon = (Connection) con.getConnection();
525525
try {
526526
SessionQueries.updateSessionInfo_Transaction(this, sqlCon, tenantIdentifier, sessionHandle,
527-
refreshTokenHash2, expiry);
527+
refreshTokenHash2, expiry, useStaticKey);
528528
} catch (SQLException e) {
529529
throw new StorageQueryException(e);
530530
}
@@ -2193,10 +2193,11 @@ public boolean updateOrDeleteExternalUserIdInfo(AppIdentifier appIdentifier, Str
21932193
}
21942194

21952195
@Override
2196-
public HashMap<String, String> getUserIdMappingForSuperTokensIds(ArrayList<String> userIds)
2196+
public HashMap<String, String> getUserIdMappingForSuperTokensIds(AppIdentifier appIdentifier,
2197+
ArrayList<String> userIds)
21972198
throws StorageQueryException {
21982199
try {
2199-
return UserIdMappingQueries.getUserIdMappingWithUserIds(this, userIds);
2200+
return UserIdMappingQueries.getUserIdMappingWithUserIds(this, appIdentifier, userIds);
22002201
} catch (SQLException e) {
22012202
throw new StorageQueryException(e);
22022203
}

src/main/java/io/supertokens/inmemorydb/queries/EmailVerificationQueries.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public static List<String> isEmailVerified_transaction(Start start, Connection s
289289
// calculating the verified emails
290290

291291
HashMap<String, String> supertokensUserIdToExternalUserIdMap = UserIdMappingQueries.getUserIdMappingWithUserIds_Transaction(start,
292-
sqlCon, supertokensUserIds);
292+
sqlCon, appIdentifier, supertokensUserIds);
293293
HashMap<String, String> externalUserIdToSupertokensUserIdMap = new HashMap<>();
294294

295295
List<String> supertokensOrExternalUserIdsToQuery = new ArrayList<>();
@@ -357,7 +357,7 @@ public static List<String> isEmailVerified(Start start, AppIdentifier appIdentif
357357
// We have external user id stored in the email verification table, so we need to fetch the mapped userids for
358358
// calculating the verified emails
359359
HashMap<String, String> supertokensUserIdToExternalUserIdMap = UserIdMappingQueries.getUserIdMappingWithUserIds(start,
360-
supertokensUserIds);
360+
appIdentifier, supertokensUserIds);
361361
HashMap<String, String> externalUserIdToSupertokensUserIdMap = new HashMap<>();
362362
List<String> supertokensOrExternalUserIdsToQuery = new ArrayList<>();
363363
for (String userId : supertokensUserIds) {

src/main/java/io/supertokens/inmemorydb/queries/SessionQueries.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,19 @@ public static SessionInfo getSessionInfo_Transaction(Start start, Connection con
147147

148148
public static void updateSessionInfo_Transaction(Start start, Connection con, TenantIdentifier tenantIdentifier,
149149
String sessionHandle,
150-
String refreshTokenHash2, long expiry)
150+
String refreshTokenHash2, long expiry, boolean useStaticKey)
151151
throws SQLException, StorageQueryException {
152152
String QUERY = "UPDATE " + getConfig(start).getSessionInfoTable()
153-
+ " SET refresh_token_hash_2 = ?, expires_at = ?"
153+
+ " SET refresh_token_hash_2 = ?, expires_at = ?, use_static_key = ?"
154154
+ " WHERE app_id = ? AND tenant_id = ? AND session_handle = ?";
155155

156156
update(con, QUERY, pst -> {
157157
pst.setString(1, refreshTokenHash2);
158158
pst.setLong(2, expiry);
159-
pst.setString(3, tenantIdentifier.getAppId());
160-
pst.setString(4, tenantIdentifier.getTenantId());
161-
pst.setString(5, sessionHandle);
159+
pst.setBoolean(3, useStaticKey);
160+
pst.setString(4, tenantIdentifier.getAppId());
161+
pst.setString(5, tenantIdentifier.getTenantId());
162+
pst.setString(6, sessionHandle);
162163
});
163164
}
164165

src/main/java/io/supertokens/inmemorydb/queries/UserIdMappingQueries.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ public static UserIdMapping[] getUserIdMappingWithEitherSuperTokensUserIdOrExter
136136

137137
}
138138

139-
public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, List<String> userIds)
139+
public static HashMap<String, String> getUserIdMappingWithUserIds(Start start,
140+
AppIdentifier appIdentifier,
141+
List<String> userIds)
140142
throws SQLException, StorageQueryException {
141143

142144
if (userIds.size() == 0) {
@@ -145,7 +147,8 @@ public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, L
145147

146148
// No need to filter based on tenantId because the id list is already filtered for a tenant
147149
StringBuilder QUERY = new StringBuilder(
148-
"SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable() + " WHERE supertokens_user_id IN (");
150+
"SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable() + " WHERE app_id = ? AND " +
151+
"supertokens_user_id IN (");
149152
for (int i = 0; i < userIds.size(); i++) {
150153
QUERY.append("?");
151154
if (i != userIds.size() - 1) {
@@ -155,9 +158,10 @@ public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, L
155158
}
156159
QUERY.append(")");
157160
return execute(start, QUERY.toString(), pst -> {
161+
pst.setString(1, appIdentifier.getAppId());
158162
for (int i = 0; i < userIds.size(); i++) {
159-
// i+1 cause this starts with 1 and not 0
160-
pst.setString(i + 1, userIds.get(i));
163+
// i+2 cause this starts with 1 and not 0, 1 is appId
164+
pst.setString(i + 2, userIds.get(i));
161165
}
162166
}, result -> {
163167
HashMap<String, String> userIdMappings = new HashMap<>();
@@ -169,7 +173,9 @@ public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, L
169173
});
170174
}
171175

172-
public static HashMap<String, String> getUserIdMappingWithUserIds_Transaction(Start start, Connection sqlCon, List<String> userIds)
176+
public static HashMap<String, String> getUserIdMappingWithUserIds_Transaction(Start start, Connection sqlCon,
177+
AppIdentifier appIdentifier,
178+
List<String> userIds)
173179
throws SQLException, StorageQueryException {
174180

175181
if (userIds.size() == 0) {
@@ -178,7 +184,8 @@ public static HashMap<String, String> getUserIdMappingWithUserIds_Transaction(St
178184

179185
// No need to filter based on tenantId because the id list is already filtered for a tenant
180186
StringBuilder QUERY = new StringBuilder(
181-
"SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable() + " WHERE supertokens_user_id IN (");
187+
"SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable() + " WHERE app_id = ? AND " +
188+
"supertokens_user_id IN (");
182189
for (int i = 0; i < userIds.size(); i++) {
183190
QUERY.append("?");
184191
if (i != userIds.size() - 1) {
@@ -188,9 +195,10 @@ public static HashMap<String, String> getUserIdMappingWithUserIds_Transaction(St
188195
}
189196
QUERY.append(")");
190197
return execute(sqlCon, QUERY.toString(), pst -> {
198+
pst.setString(1, appIdentifier.getAppId());
191199
for (int i = 0; i < userIds.size(); i++) {
192-
// i+1 cause this starts with 1 and not 0
193-
pst.setString(i + 1, userIds.get(i));
200+
// i+2 cause this starts with 1 and not 0, 1 is appId
201+
pst.setString(i + 2, userIds.get(i));
194202
}
195203
}, result -> {
196204
HashMap<String, String> userIdMappings = new HashMap<>();

0 commit comments

Comments
 (0)