diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-01-20 15:22:26 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-01-20 15:22:26 +0000 |
commit | e19dd8c31f2128b77ee08c8475919829b89d5e4f (patch) | |
tree | 6ddf0bbb5ddf4af58e3545a1d444bf4dd2c521be /app/src/main/java | |
parent | 569283ea93dba6816df092e702b97f6d5c956ebf (diff) | |
download | infinity-for-reddit-e19dd8c31f2128b77ee08c8475919829b89d5e4f.tar infinity-for-reddit-e19dd8c31f2128b77ee08c8475919829b89d5e4f.tar.gz infinity-for-reddit-e19dd8c31f2128b77ee08c8475919829b89d5e4f.tar.bz2 infinity-for-reddit-e19dd8c31f2128b77ee08c8475919829b89d5e4f.tar.lz infinity-for-reddit-e19dd8c31f2128b77ee08c8475919829b89d5e4f.tar.xz infinity-for-reddit-e19dd8c31f2128b77ee08c8475919829b89d5e4f.tar.zst infinity-for-reddit-e19dd8c31f2128b77ee08c8475919829b89d5e4f.zip |
Make OAuth2 API change: https://www.reddit.com/r/redditdev/comments/kvzaot/oauth2_api_changes_upcoming/
Diffstat (limited to 'app/src/main/java')
3 files changed, 9 insertions, 7 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java index 19407839..3c912221 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java @@ -69,9 +69,10 @@ class AccessTokenAuthenticator implements Authenticator { try { retrofit2.Response<String> response = accessTokenCall.execute(); if (response.isSuccessful() && response.body() != null) { - JSONObject jsonObject = new JSONObject((String) response.body()); + JSONObject jsonObject = new JSONObject(response.body()); String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY); - mRedditDataRoomDatabase.accountDao().changeAccessToken(account.getUsername(), newAccessToken); + String newRefreshToken = jsonObject.getString(APIUtils.REFRESH_TOKEN_KEY); + mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getUsername(), newAccessToken, newRefreshToken); return newAccessToken; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java index 538c4a2c..561f393b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java @@ -245,11 +245,12 @@ public class PullNotificationWorker extends Worker { Call<String> accessTokenCall = api.getAccessToken(APIUtils.getHttpBasicAuthHeader(), params); try { - Response response = accessTokenCall.execute(); + Response<String> response = accessTokenCall.execute(); if (response.isSuccessful() && response.body() != null) { - JSONObject jsonObject = new JSONObject(response.body().toString()); + JSONObject jsonObject = new JSONObject(response.body()); String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY); - mRedditDataRoomDatabase.accountDao().changeAccessToken(account.getUsername(), newAccessToken); + String newRefreshToken = jsonObject.getString(APIUtils.REFRESH_TOKEN_KEY); + mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getUsername(), newAccessToken, newRefreshToken); return newAccessToken; } return ""; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/account/AccountDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/account/AccountDao.java index 076f76f1..0f214f85 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/account/AccountDao.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/account/AccountDao.java @@ -50,6 +50,6 @@ public interface AccountDao { @Query("UPDATE accounts SET is_current_user = 1 WHERE username = :username") void markAccountCurrent(String username); - @Query("UPDATE accounts SET access_token = :accessToken WHERE username = :username") - void changeAccessToken(String username, String accessToken); + @Query("UPDATE accounts SET access_token = :accessToken, refresh_token = :refreshToken WHERE username = :username") + void updateAccessTokenAndRefreshToken(String username, String accessToken, String refreshToken); } |