Skip to content

Commit 87e64f2

Browse files
authored
feat: make refresh update the signing key type of sessions (#180)
1 parent 08043dc commit 87e64f2

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

CHANGELOG.md

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

1010
- Replace `TotpNotEnabledError` with `UnknownUserIdTotpError`.
1111
- Support for MFA recipe
12+
- Adds a new `useStaticKey` param to `updateSessionInfo_Transaction`
13+
- This enables smooth switching between `useDynamicAccessTokenSigningKey` settings by allowing refresh calls to
14+
change the signing key type of a session
1215

1316
## [5.0.6] - 2023-12-05
1417

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,11 @@ public SessionInfo getSessionInfo_Transaction(TenantIdentifier tenantIdentifier,
644644
@Override
645645
public void updateSessionInfo_Transaction(TenantIdentifier tenantIdentifier, TransactionConnection con,
646646
String sessionHandle, String refreshTokenHash2,
647-
long expiry) throws StorageQueryException {
647+
long expiry, boolean useStaticKey) throws StorageQueryException {
648648
Connection sqlCon = (Connection) con.getConnection();
649649
try {
650650
SessionQueries.updateSessionInfo_Transaction(this, sqlCon, tenantIdentifier, sessionHandle,
651-
refreshTokenHash2, expiry);
651+
refreshTokenHash2, expiry, useStaticKey);
652652
} catch (SQLException e) {
653653
throw new StorageQueryException(e);
654654
}

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

0 commit comments

Comments
 (0)