Merge branch 'develop' into Peertube_stream

This commit is contained in:
stom79 2019-01-06 14:45:01 +01:00
commit 0b2cc78be3
3 changed files with 25 additions and 3 deletions

View File

@ -64,7 +64,6 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
Account account = null;
if( social == SOCIAL.MASTODON) {
account = new API(this.contextReference.get(), instance, null).verifyCredentials();
account.setSocial("MASTODON");
@ -75,8 +74,10 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
}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( values.get("access_token") != null)
this.token = values.get("access_token");
if( values.get("refresh_token") != null)
this.refresh_token = values.get("refresh_token");
}
}
}

View File

@ -20,6 +20,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
@ -65,6 +66,25 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void>
} catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
}
try {
account = new PeertubeAPI(this.contextReference.get()).verifyCredentials();
account.setSocial("PEERTUBE");
}catch (HttpsConnection.HttpsConnectionException exception){
if(exception.getStatusCode() == 401){
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
account = new AccountDAO(this.contextReference.get(), db).getAccountByToken(token);
HashMap<String, String> values = new PeertubeAPI(this.contextReference.get()).refreshToken(account.getClient_id(), account.getClient_secret(), account.getRefresh_token().trim());
String newtoken = values.get("access_token");
String refresh_token = values.get("refresh_token");
if( newtoken != null)
account.setToken(newtoken);
if( refresh_token != null)
account.setRefresh_token(refresh_token);
new AccountDAO(this.contextReference.get(), db).updateAccount(account);
}
}
}
if( account == null)
return null;

View File

@ -236,6 +236,7 @@ public class PeertubeAPI {
params.put("client_id", client_id);
params.put("client_secret", client_secret);
params.put("refresh_token", refresh_token);
try {
String response = new HttpsConnection(context).post(getAbsoluteUrl("/users/token"), 60, params, null);
JSONObject resobj = new JSONObject(response);