From 8f28489d38d3346eee479769772b437dbd995ddc Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Mar 2026 15:46:51 -0700 Subject: [PATCH] Fix bug storing credentials in Keychain when there's a previous item. --- Modules/Secrets/Sources/Secrets/CredentialsManager.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Modules/Secrets/Sources/Secrets/CredentialsManager.swift b/Modules/Secrets/Sources/Secrets/CredentialsManager.swift index e7e5f3bde..52d8076f4 100644 --- a/Modules/Secrets/Sources/Secrets/CredentialsManager.swift +++ b/Modules/Secrets/Sources/Secrets/CredentialsManager.swift @@ -85,8 +85,14 @@ public struct CredentialsManager { throw error } + // Remove kSecValueData so the delete matches by identity + // (server, username, type) regardless of the stored secret. + // Without this, the delete fails when the token has changed + // (as during an OAuth refresh), and the re-add fails + // with errSecDuplicateItem. var deleteQuery = query deleteQuery.removeValue(forKey: kSecAttrAccessible as String) + deleteQuery.removeValue(forKey: kSecValueData as String) SecItemDelete(deleteQuery as CFDictionary) let addStatus = SecItemAdd(query as CFDictionary, nil)