Fix refresh token
This commit is contained in:
parent
abe8812e6e
commit
42b17d8d71
|
@ -586,7 +586,8 @@ public class LoginActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
JSONObject resobj;
|
JSONObject resobj;
|
||||||
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU && socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU && socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
resobj = new JSONObject(response);
|
resobj = new JSONObject(response);
|
||||||
String token = resobj.getString("access_token");
|
String token = resobj.getString("access_token");
|
||||||
|
@ -607,7 +608,8 @@ public class LoginActivity extends BaseActivity {
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
resobj = new JSONObject(response);
|
resobj = new JSONObject(response);
|
||||||
Account account = GNUAPI.parseAccountResponse(resobj);
|
Account account = GNUAPI.parseAccountResponse(resobj);
|
||||||
|
@ -623,9 +625,10 @@ public class LoginActivity extends BaseActivity {
|
||||||
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin());
|
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin());
|
||||||
editor.putString(Helper.PREF_INSTANCE, instance);
|
editor.putString(Helper.PREF_INSTANCE, instance);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
if (userExists)
|
if (userExists) {
|
||||||
|
|
||||||
new AccountDAO(LoginActivity.this, db).updateAccount(account);
|
new AccountDAO(LoginActivity.this, db).updateAccount(account);
|
||||||
else {
|
}else {
|
||||||
if (account.getUsername() != null && account.getCreated_at() != null)
|
if (account.getUsername() != null && account.getCreated_at() != null)
|
||||||
new AccountDAO(LoginActivity.this, db).insertAccount(account);
|
new AccountDAO(LoginActivity.this, db).insertAccount(account);
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
account.setClient_secret(client_secret);
|
account.setClient_secret(client_secret);
|
||||||
account.setRefresh_token(refresh_token);
|
account.setRefresh_token(refresh_token);
|
||||||
account.setInstance(instance);
|
account.setInstance(instance);
|
||||||
|
|
||||||
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
boolean userExists = new AccountDAO(this.contextReference.get(), db).userExist(account);
|
boolean userExists = new AccountDAO(this.contextReference.get(), db).userExist(account);
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
|
|
@ -80,7 +80,6 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void>
|
||||||
account.setClient_secret(accountOld.getClient_secret());
|
account.setClient_secret(accountOld.getClient_secret());
|
||||||
new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account);
|
new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
|
if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
|
||||||
new API(contextReference.get()).refreshToken(account);
|
new API(contextReference.get()).refreshToken(account);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2552,6 +2552,7 @@ public class API {
|
||||||
try {
|
try {
|
||||||
String response;
|
String response;
|
||||||
if (account.getSocial().compareTo("PEERTUBE") == 0) {
|
if (account.getSocial().compareTo("PEERTUBE") == 0) {
|
||||||
|
|
||||||
response = new HttpsConnection(context, instance).post(getAbsoluteUrl("/users/token"), 60, params, null);
|
response = new HttpsConnection(context, instance).post(getAbsoluteUrl("/users/token"), 60, params, null);
|
||||||
} else {
|
} else {
|
||||||
response = new HttpsConnection(context, instance).post("https://" + instance + "/oauth/token", 60, params, null);
|
response = new HttpsConnection(context, instance).post("https://" + instance + "/oauth/token", 60, params, null);
|
||||||
|
@ -2573,6 +2574,11 @@ public class API {
|
||||||
}
|
}
|
||||||
account.setRefresh_token(newRefreshToken);
|
account.setRefresh_token(newRefreshToken);
|
||||||
account.setToken(newToken);
|
account.setToken(newToken);
|
||||||
|
if( account.getHeader() == null){
|
||||||
|
account.setHeader("");
|
||||||
|
account.setHeader_static("");
|
||||||
|
}
|
||||||
|
account.setInstance(instance);
|
||||||
new AccountDAO(context, db).updateAccount(account);
|
new AccountDAO(context, db).updateAccount(account);
|
||||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -123,7 +123,9 @@ public class AccountDAO {
|
||||||
values.put(Sqlite.COL_HEADER_STATIC, account.getHeader_static());
|
values.put(Sqlite.COL_HEADER_STATIC, account.getHeader_static());
|
||||||
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at()));
|
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at()));
|
||||||
values.put(Sqlite.COL_EMOJIS, Helper.emojisToStringStorage(account.getEmojis()));
|
values.put(Sqlite.COL_EMOJIS, Helper.emojisToStringStorage(account.getEmojis()));
|
||||||
values.put(Sqlite.COL_SOCIAL, account.getSocial());
|
if( account.getSocial() != null) {
|
||||||
|
values.put(Sqlite.COL_SOCIAL, account.getSocial());
|
||||||
|
}
|
||||||
if (account.getClient_id() != null && account.getClient_secret() != null) {
|
if (account.getClient_id() != null && account.getClient_secret() != null) {
|
||||||
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
|
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
|
||||||
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
|
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
|
||||||
|
@ -131,11 +133,18 @@ public class AccountDAO {
|
||||||
if (account.getRefresh_token() != null) {
|
if (account.getRefresh_token() != null) {
|
||||||
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
|
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account.getToken() != null)
|
if (account.getToken() != null)
|
||||||
values.put(Sqlite.COL_OAUTHTOKEN, account.getToken());
|
values.put(Sqlite.COL_OAUTHTOKEN, account.getToken());
|
||||||
return db.update(Sqlite.TABLE_USER_ACCOUNT,
|
|
||||||
values, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",
|
try {
|
||||||
new String[]{account.getId(), account.getInstance()});
|
return db.update(Sqlite.TABLE_USER_ACCOUNT,
|
||||||
|
values, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",
|
||||||
|
new String[]{account.getId(), account.getInstance()});
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue