         didSet {
             if let credentials = credentials {
                 _ = try? keychain.set(credentials, key: OAuthClient.credentials)
+            }
+            else {
+                _ = try? keychain.remove(OAuthClient.credentials)
             }
             // If there were credentials, and there no longer are, post a notification
             if oldValue != nil && credentials == nil {

import KeychainAccess

/// OAuthClient manages the OAuth requests. It is responsible for:
/// - the inital login which obtains the refresh token
/// - refreshing the token when it expires
/// - adding authentication token to APIClient requests
/// - retrying APIClient requests on authorization failures.
final class OAuthClient {
    static let credentials = "credentials"

    var clientSecret = BuildType.active.oathClientToken
    var clientID = BuildType.active.oathClientID

        self.manager = SessionManager(configuration: configuration)

        if let credentials: Credentials? = try? keychain.getObject(OAuthClient.credentials) {
            if OAuthClient.validKeychain {
                self.credentials = credentials
            }
            else {
                self.credentials = nil
            }
        }
        OAuthClient.validKeychain = true
    }
}

