Fix bug storing credentials in Keychain when there's a previous item.

This commit is contained in:
Brent Simmons committed 2026-03-18 15:46:51 -07:00
1 parent 1f893d0197
commit 8f28489d38
1 file changed
+6
@@ -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)