Skip to content

Commit 8f2c06c

Browse files
authored
fix: backport to core 6.0 (#214)
1 parent 3e55975 commit 8f2c06c

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
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+
## [4.0.5] - 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
## [4.0.4] - 2024-02-20
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 = "4.0.4"
5+
version = "4.0.5"
66

77
repositories {
88
mavenCentral()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,11 @@ public SessionInfo getSessionInfo_Transaction(TenantIdentifier tenantIdentifier,
642642
@Override
643643
public void updateSessionInfo_Transaction(TenantIdentifier tenantIdentifier, TransactionConnection con,
644644
String sessionHandle, String refreshTokenHash2,
645-
long expiry) throws StorageQueryException {
645+
long expiry, boolean useStaticKey) throws StorageQueryException {
646646
Connection sqlCon = (Connection) con.getConnection();
647647
try {
648648
SessionQueries.updateSessionInfo_Transaction(this, sqlCon, tenantIdentifier, sessionHandle,
649-
refreshTokenHash2, expiry);
649+
refreshTokenHash2, expiry, useStaticKey);
650650
} catch (SQLException e) {
651651
throw new StorageQueryException(e);
652652
}
@@ -2244,10 +2244,10 @@ 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, ArrayList<String> userIds)
22482248
throws StorageQueryException {
22492249
try {
2250-
return UserIdMappingQueries.getUserIdMappingWithUserIds(this, userIds);
2250+
return UserIdMappingQueries.getUserIdMappingWithUserIds(this, appIdentifier, userIds);
22512251
} catch (SQLException e) {
22522252
throw new StorageQueryException(e);
22532253
}

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

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

142142
public static void updateSessionInfo_Transaction(Start start, Connection con, TenantIdentifier tenantIdentifier,
143143
String sessionHandle,
144-
String refreshTokenHash2, long expiry)
144+
String refreshTokenHash2, long expiry, boolean useStaticKey)
145145
throws SQLException, StorageQueryException {
146146
String QUERY = "UPDATE " + getConfig(start).getSessionInfoTable()
147-
+ " SET refresh_token_hash_2 = ?, expires_at = ?"
147+
+ " SET refresh_token_hash_2 = ?, expires_at = ?, use_static_key = ?"
148148
+ " WHERE app_id = ? AND tenant_id = ? AND session_handle = ?";
149149

150150
update(con, QUERY, pst -> {
151151
pst.setString(1, refreshTokenHash2);
152152
pst.setLong(2, expiry);
153-
pst.setString(3, tenantIdentifier.getAppId());
154-
pst.setString(4, tenantIdentifier.getTenantId());
155-
pst.setString(5, sessionHandle);
153+
pst.setBoolean(3, useStaticKey);
154+
pst.setString(4, tenantIdentifier.getAppId());
155+
pst.setString(5, tenantIdentifier.getTenantId());
156+
pst.setString(6, sessionHandle);
156157
});
157158
}
158159

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

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

127127
}
128128

129-
public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, ArrayList<String> userIds)
129+
public static HashMap<String, String> getUserIdMappingWithUserIds(Start start,
130+
AppIdentifier appIdentifier,
131+
ArrayList<String> userIds)
130132
throws SQLException, StorageQueryException {
131133

132134
if (userIds.size() == 0) {
@@ -135,7 +137,8 @@ public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, A
135137

136138
// No need to filter based on tenantId because the id list is already filtered for a tenant
137139
StringBuilder QUERY = new StringBuilder(
138-
"SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable() + " WHERE supertokens_user_id IN (");
140+
"SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable() + " WHERE app_id = ? AND " +
141+
"supertokens_user_id IN (");
139142
for (int i = 0; i < userIds.size(); i++) {
140143
QUERY.append("?");
141144
if (i != userIds.size() - 1) {
@@ -145,9 +148,10 @@ public static HashMap<String, String> getUserIdMappingWithUserIds(Start start, A
145148
}
146149
QUERY.append(")");
147150
return execute(start, QUERY.toString(), pst -> {
151+
pst.setString(1, appIdentifier.getAppId());
148152
for (int i = 0; i < userIds.size(); i++) {
149-
// i+1 cause this starts with 1 and not 0
150-
pst.setString(i + 1, userIds.get(i));
153+
// i+2 cause this starts with 1 and not 0, and 1 is the app_id
154+
pst.setString(i + 2, userIds.get(i));
151155
}
152156
}, result -> {
153157
HashMap<String, String> userIdMappings = new HashMap<>();

0 commit comments

Comments
 (0)