From 4c324e92df1f1edad7b64e8095809768d6497870 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 4 Mar 2020 12:58:06 -0600 Subject: [PATCH] Create new http client when fetching user info --- .../java/org/tasks/etesync/EteSyncClient.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/tasks/etesync/EteSyncClient.java b/app/src/main/java/org/tasks/etesync/EteSyncClient.java index ef6b20829..83cb221c2 100644 --- a/app/src/main/java/org/tasks/etesync/EteSyncClient.java +++ b/app/src/main/java/org/tasks/etesync/EteSyncClient.java @@ -102,6 +102,7 @@ public class EteSyncClient { this.username = username; this.encryptionPassword = encryptionPassword; this.token = token; + this.foreground = foreground; CustomCertManager customCertManager = new CustomCertManager(context); customCertManager.setAppInForeground(foreground); @@ -151,10 +152,25 @@ public class EteSyncClient { foreground); } - Pair getInfoAndToken(String password) throws IOException, HttpException { + private EteSyncClient withToken(String token) + throws KeyManagementException, NoSuchAlgorithmException { + return new EteSyncClient( + context, + encryption, + preferences, + interceptor, + httpUrl.toString(), + username, + encryptionPassword, + token, + foreground); + } + + Pair getInfoAndToken(String password) + throws IOException, HttpException, NoSuchAlgorithmException, KeyManagementException { JournalAuthenticator journalAuthenticator = new JournalAuthenticator(httpClient, httpUrl); String token = journalAuthenticator.getAuthToken(username, password); - return Pair.create(getUserInfo(), token); + return Pair.create(withToken(token).getUserInfo(), token); } UserInfo getUserInfo() throws HttpException { @@ -226,7 +242,7 @@ public class EteSyncClient { void invalidateToken() { try { - new JournalAuthenticator(httpClient, httpUrl).invalidateAuthToken(token); + new JournalAuthenticator(httpClient, httpUrl).invalidateAuthToken(token); } catch (Exception e) { Timber.e(e); }