From 1a1eecac648afb1aef64efed649477973b5b6f0a Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Fri, 24 Nov 2023 14:16:54 +0100 Subject: [PATCH] Delete authentication credentials from Keychain upon logout Fixes #1181 --- .../MastodonCore/AuthenticationServiceProvider.swift | 3 ++- .../MastodonCore/Service/AuthenticationService.swift | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift b/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift index 1d8b2d6cc..ec706cc98 100644 --- a/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift +++ b/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift @@ -30,7 +30,8 @@ public class AuthenticationServiceProvider: ObservableObject { } } - func delete(authentication: MastodonAuthentication) { + func delete(authentication: MastodonAuthentication) throws { + try Self.keychain.remove(authentication.persistenceIdentifier) authentications.removeAll(where: { $0 == authentication }) } diff --git a/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift b/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift index 71c619f19..8c7963a19 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift @@ -150,8 +150,12 @@ extension AuthenticationService { for feed in feeds { managedObjectContext.delete(feed) } - - AuthenticationServiceProvider.shared.delete(authentication: authenticationBox.authentication) + } + + do { + try AuthenticationServiceProvider.shared.delete(authentication: authenticationBox.authentication) + } catch { + assertionFailure("Failed to delete Authentication: \(error)") } // cancel push notification subscription