mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-16 21:23:07 +01:00
Handle no new refresh token.
This commit is contained in:
parent
e19dd8c31f
commit
4ae21a18f0
@ -10,8 +10,8 @@ import java.io.IOException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
|
|
||||||
import ml.docilealligator.infinityforreddit.account.Account;
|
import ml.docilealligator.infinityforreddit.account.Account;
|
||||||
|
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
|
||||||
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
||||||
import okhttp3.Authenticator;
|
import okhttp3.Authenticator;
|
||||||
import okhttp3.Headers;
|
import okhttp3.Headers;
|
||||||
@ -71,8 +71,12 @@ class AccessTokenAuthenticator implements Authenticator {
|
|||||||
if (response.isSuccessful() && response.body() != null) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
JSONObject jsonObject = new JSONObject(response.body());
|
JSONObject jsonObject = new JSONObject(response.body());
|
||||||
String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY);
|
String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY);
|
||||||
String newRefreshToken = jsonObject.getString(APIUtils.REFRESH_TOKEN_KEY);
|
String newRefreshToken = jsonObject.has(APIUtils.REFRESH_TOKEN_KEY) ? jsonObject.getString(APIUtils.REFRESH_TOKEN_KEY) : null;
|
||||||
mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getUsername(), newAccessToken, newRefreshToken);
|
if (newRefreshToken == null) {
|
||||||
|
mRedditDataRoomDatabase.accountDao().updateAccessToken(account.getUsername(), newAccessToken);
|
||||||
|
} else {
|
||||||
|
mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getUsername(), newAccessToken, newRefreshToken);
|
||||||
|
}
|
||||||
|
|
||||||
return newAccessToken;
|
return newAccessToken;
|
||||||
}
|
}
|
||||||
|
@ -249,8 +249,12 @@ public class PullNotificationWorker extends Worker {
|
|||||||
if (response.isSuccessful() && response.body() != null) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
JSONObject jsonObject = new JSONObject(response.body());
|
JSONObject jsonObject = new JSONObject(response.body());
|
||||||
String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY);
|
String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY);
|
||||||
String newRefreshToken = jsonObject.getString(APIUtils.REFRESH_TOKEN_KEY);
|
String newRefreshToken = jsonObject.has(APIUtils.REFRESH_TOKEN_KEY) ? jsonObject.getString(APIUtils.REFRESH_TOKEN_KEY) : null;
|
||||||
mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getUsername(), newAccessToken, newRefreshToken);
|
if (newRefreshToken == null) {
|
||||||
|
mRedditDataRoomDatabase.accountDao().updateAccessToken(account.getUsername(), newAccessToken);
|
||||||
|
} else {
|
||||||
|
mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getUsername(), newAccessToken, newRefreshToken);
|
||||||
|
}
|
||||||
return newAccessToken;
|
return newAccessToken;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
@ -52,4 +52,7 @@ public interface AccountDao {
|
|||||||
|
|
||||||
@Query("UPDATE accounts SET access_token = :accessToken, refresh_token = :refreshToken WHERE username = :username")
|
@Query("UPDATE accounts SET access_token = :accessToken, refresh_token = :refreshToken WHERE username = :username")
|
||||||
void updateAccessTokenAndRefreshToken(String username, String accessToken, String refreshToken);
|
void updateAccessTokenAndRefreshToken(String username, String accessToken, String refreshToken);
|
||||||
|
|
||||||
|
@Query("UPDATE accounts SET access_token = :accessToken WHERE username = :username")
|
||||||
|
void updateAccessToken(String username, String accessToken);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user