Fix refresh token issue
This commit is contained in:
parent
2636b86e3e
commit
4c51a7c7e8
|
@ -776,6 +776,7 @@ public class PeertubeAPI {
|
|||
account.setRefresh_token(newRefreshToken);
|
||||
account.setToken(newToken);
|
||||
}
|
||||
account.setInstance(instance);
|
||||
new AccountDAO(context, db).updateAccount(account);
|
||||
}
|
||||
}
|
||||
|
@ -1161,29 +1162,6 @@ public class PeertubeAPI {
|
|||
try {
|
||||
return getTL("/users/me/subscriptions/videos", "-publishedAt", null, max_id, null, null);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
if (targetedAccount != null && (e.getStatusCode() == 401 || e.getStatusCode() == 403)) {
|
||||
HashMap<String, String> values = refreshToken(targetedAccount.getClient_id(), targetedAccount.getClient_secret(), targetedAccount.getRefresh_token());
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
if (values.containsKey("access_token") && values.get("access_token") != null) {
|
||||
targetedAccount.setToken(values.get("access_token"));
|
||||
//This account is currently logged in, the token is updated
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
prefKeyOauthTokenT = targetedAccount.getToken();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, targetedAccount.getToken());
|
||||
editor.apply();
|
||||
}
|
||||
if (values.containsKey("refresh_token") && values.get("refresh_token") != null)
|
||||
targetedAccount.setRefresh_token(values.get("refresh_token"));
|
||||
new AccountDAO(context, db).updateAccount(targetedAccount);
|
||||
try {
|
||||
return getTL("/users/me/subscriptions/videos", "-publishedAt", null, max_id, null, null);
|
||||
} catch (HttpsConnection.HttpsConnectionException e1) {
|
||||
setError(e.getStatusCode(), e);
|
||||
return apiResponse;
|
||||
}
|
||||
}
|
||||
setError(e.getStatusCode(), e);
|
||||
return apiResponse;
|
||||
}
|
||||
|
|
|
@ -68,9 +68,11 @@ public class AccountDAO {
|
|||
values.put(Sqlite.COL_HEADER_STATIC, account.getHeader_static());
|
||||
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at()));
|
||||
values.put(Sqlite.COL_INSTANCE, account.getInstance());
|
||||
if (account.getClient_id() != null && account.getClient_secret() != null && account.getRefresh_token() != null) {
|
||||
if (account.getClient_id() != null && account.getClient_secret() != null ) {
|
||||
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
|
||||
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
|
||||
}
|
||||
if( account.getRefresh_token() != null) {
|
||||
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
|
||||
}
|
||||
if (account.getToken() != null)
|
||||
|
@ -114,9 +116,11 @@ public class AccountDAO {
|
|||
values.put(Sqlite.COL_HEADER, account.getHeader());
|
||||
values.put(Sqlite.COL_HEADER_STATIC, account.getHeader_static());
|
||||
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at()));
|
||||
if (account.getClient_id() != null && account.getClient_secret() != null && account.getRefresh_token() != null) {
|
||||
if (account.getClient_id() != null && account.getClient_secret() != null) {
|
||||
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
|
||||
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
|
||||
}
|
||||
if( account.getRefresh_token() != null) {
|
||||
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
|
||||
}
|
||||
if (account.getToken() != null)
|
||||
|
@ -153,9 +157,11 @@ public class AccountDAO {
|
|||
values.put(Sqlite.COL_HEADER_STATIC, account.getHeader_static());
|
||||
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at()));
|
||||
|
||||
if (account.getClient_id() != null && account.getClient_secret() != null && account.getRefresh_token() != null) {
|
||||
if (account.getClient_id() != null && account.getClient_secret() != null) {
|
||||
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
|
||||
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
|
||||
}
|
||||
if( account.getRefresh_token() != null) {
|
||||
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
|
||||
}
|
||||
if (account.getToken() != null)
|
||||
|
|
Loading…
Reference in New Issue