diff options
author | stom79 <tschneider.ac@gmail.com> | 2019-01-05 13:00:15 +0100 |
---|---|---|
committer | stom79 <tschneider.ac@gmail.com> | 2019-01-05 13:00:15 +0100 |
commit | 4d8547fe5292956c54b8dc09c49098afdc9fb36f (patch) | |
tree | 0aed3bd5f668213b2133dcd5316ef3d8fcc97b79 /app/src/main/java/fr/gouv/etalab/mastodon/asynctasks | |
parent | eefe1edc3b8cd924d0892a2d1aa53e3ce21ec558 (diff) |
Refresh the token when expired #699
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/asynctasks')
-rw-r--r-- | app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java | 14 | ||||
-rw-r--r-- | app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java | 10 |
2 files changed, 20 insertions, 4 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java index bc229298e..12e711ade 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java @@ -24,10 +24,12 @@ import android.os.AsyncTask; import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; import java.net.URLDecoder; +import java.util.HashMap; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.Entities.Account; +import fr.gouv.etalab.mastodon.client.HttpsConnection; import fr.gouv.etalab.mastodon.client.PeertubeAPI; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; @@ -67,8 +69,16 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> { account = new API(this.contextReference.get(), instance, null).verifyCredentials(); account.setSocial("MASTODON"); }else if( social == SOCIAL.PEERTUBE) { - account = new PeertubeAPI(this.contextReference.get(), instance, null).verifyCredentials(); - account.setSocial("PEERTUBE"); + try { + account = new PeertubeAPI(this.contextReference.get(), instance, null).verifyCredentials(); + account.setSocial("PEERTUBE"); + }catch (HttpsConnection.HttpsConnectionException exception){ + if(exception.getStatusCode() == 401){ + HashMap<String, String> values = new PeertubeAPI(this.contextReference.get(), instance, null).refreshToken(client_id, client_secret, refresh_token); + this.token = values.get("access_token"); + this.refresh_token = values.get("refresh_token"); + } + } } if( account == null) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java index 47d7de422..a402fdd57 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java @@ -25,6 +25,7 @@ import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Emojis; +import fr.gouv.etalab.mastodon.client.HttpsConnection; import fr.gouv.etalab.mastodon.client.PeertubeAPI; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnUpdateAccountInfoInterface; @@ -58,8 +59,13 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void> Account account = null; if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) account = new API(this.contextReference.get()).getAccount(userId); - else if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) - account = new PeertubeAPI(this.contextReference.get()).verifyCredentials(); + else if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) { + try { + account = new PeertubeAPI(this.contextReference.get()).verifyCredentials(); + } catch (HttpsConnection.HttpsConnectionException e) { + e.printStackTrace(); + } + } if( account == null) return null; account.setInstance(Helper.getLiveInstance(contextReference.get())); |