From 5857ed51d0c743f7072d22e03e2073a91ecf7bc9 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 23 Jan 2020 19:59:46 +0200 Subject: [PATCH] Logout: invalidate the auth token after logging out. --- .../etesync/syncadapter/ui/AccountActivity.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt b/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt index 0d713376..58b8ea1d 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt @@ -29,6 +29,8 @@ import at.bitfire.ical4android.TaskProvider import at.bitfire.vcard4android.ContactsStorageException import com.etesync.syncadapter.* import com.etesync.syncadapter.journalmanager.Crypto +import com.etesync.syncadapter.journalmanager.Exceptions +import com.etesync.syncadapter.journalmanager.JournalAuthenticator import com.etesync.syncadapter.log.Logger import com.etesync.syncadapter.model.CollectionInfo import com.etesync.syncadapter.model.JournalEntity @@ -41,6 +43,8 @@ import com.etesync.syncadapter.utils.HintManager import com.etesync.syncadapter.utils.ShowcaseBuilder import com.etesync.syncadapter.utils.packageInstalled import com.google.android.material.snackbar.Snackbar +import okhttp3.HttpUrl +import org.jetbrains.anko.doAsync import tourguide.tourguide.ToolTip import java.util.logging.Level @@ -412,6 +416,20 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe private fun deleteAccount() { val accountManager = AccountManager.get(this) + val settings = AccountSettings(this@AccountActivity, account) + val authToken = settings.authToken + val principal = HttpUrl.get(settings.uri!!) + + doAsync { + try { + val httpClient = HttpClient.Builder(this@AccountActivity, null, authToken).build().okHttpClient + val journalAuthenticator = JournalAuthenticator(httpClient, principal!!) + journalAuthenticator.invalidateAuthToken(authToken) + } catch (e: Exceptions.HttpException) { + // Ignore failures for now + Logger.log.warning(e.toString()) + } + } if (Build.VERSION.SDK_INT >= 22) accountManager.removeAccount(account, this, { future ->