diff options
author | Alexander Tkachev | 2019-07-15 22:14:23 +0700 |
---|---|---|
committer | Matan Bareket | 2019-07-30 14:51:41 -0400 |
commit | 60504dce7539863a207610fd636236c7035ade3e (patch) | |
tree | dc4eee3a5740f206e08edb2d93fa6df0eefe4ed2 /backends/cloud/googledrive | |
parent | 4a427faf9cc817cfce8e293c22cc470339b6e3c7 (diff) | |
download | scummvm-rg350-60504dce7539863a207610fd636236c7035ade3e.tar.gz scummvm-rg350-60504dce7539863a207610fd636236c7035ade3e.tar.bz2 scummvm-rg350-60504dce7539863a207610fd636236c7035ade3e.zip |
CLOUD: Update storages to refresh token via cloud.scummvm.org
Diffstat (limited to 'backends/cloud/googledrive')
-rw-r--r-- | backends/cloud/googledrive/googledrivestorage.cpp | 55 | ||||
-rw-r--r-- | backends/cloud/googledrive/googledrivestorage.h | 10 |
2 files changed, 3 insertions, 62 deletions
diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp index a2f688a1e7..be81629cef 100644 --- a/backends/cloud/googledrive/googledrivestorage.cpp +++ b/backends/cloud/googledrive/googledrivestorage.cpp @@ -56,60 +56,7 @@ Common::String GoogleDriveStorage::cloudProvider() { return "gdrive"; } uint32 GoogleDriveStorage::storageIndex() { return kStorageGoogleDriveId; } -void GoogleDriveStorage::refreshAccessToken(BoolCallback callback, Networking::ErrorCallback errorCallback) { - if (_refreshToken == "") { - warning("GoogleDriveStorage: no refresh token available to get new access token."); - if (callback) - (*callback)(BoolResponse(nullptr, false)); - return; - } - - Networking::JsonCallback innerCallback = new Common::CallbackBridge<GoogleDriveStorage, BoolResponse, Networking::JsonResponse>(this, &GoogleDriveStorage::tokenRefreshed, callback); - if (errorCallback == nullptr) - errorCallback = getErrorPrintingCallback(); - - Common::String url = "https://cloud.scummvm.org/gdrive/refresh/" + _refreshToken; // TODO: subject to change - Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(innerCallback, errorCallback, url); - addRequest(request); -} - -void GoogleDriveStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResponse response) { - Common::JSONValue *json = response.value; - if (!json) { - warning("GoogleDriveStorage: got NULL instead of JSON"); - if (callback) - (*callback)(BoolResponse(nullptr, false)); - delete callback; - return; - } - - if (!Networking::CurlJsonRequest::jsonIsObject(json, "GoogleDriveStorage")) { - if (callback) - (*callback)(BoolResponse(nullptr, false)); - delete json; - delete callback; - return; - } - - Common::JSONObject result = json->asObject(); - if (!Networking::CurlJsonRequest::jsonContainsString(result, "access_token", "GoogleDriveStorage")) { - warning("GoogleDriveStorage: bad response, no token passed"); - debug(9, "%s", json->stringify().c_str()); - if (callback) - (*callback)(BoolResponse(nullptr, false)); - } else { - _token = result.getVal("access_token")->asString(); - if (!Networking::CurlJsonRequest::jsonContainsString(result, "refresh_token", "GoogleDriveStorage")) - warning("GoogleDriveStorage: no refresh_token passed"); - else - _refreshToken = result.getVal("refresh_token")->asString(); - CloudMan.save(); //ask CloudManager to save our new refreshToken - if (callback) - (*callback)(BoolResponse(nullptr, true)); - } - delete json; - delete callback; -} +bool GoogleDriveStorage::needsRefreshToken() { return true; } void GoogleDriveStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain); diff --git a/backends/cloud/googledrive/googledrivestorage.h b/backends/cloud/googledrive/googledrivestorage.h index 30bc9ab3f5..730e8e20c3 100644 --- a/backends/cloud/googledrive/googledrivestorage.h +++ b/backends/cloud/googledrive/googledrivestorage.h @@ -33,8 +33,6 @@ class GoogleDriveStorage: public Id::IdStorage { /** This private constructor is called from loadFromConfig(). */ GoogleDriveStorage(Common::String token, Common::String refreshToken); - void tokenRefreshed(BoolCallback callback, Networking::JsonResponse response); - /** Constructs StorageInfo based on JSON response from cloud. */ void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json); @@ -54,6 +52,8 @@ protected: */ virtual uint32 storageIndex(); + virtual bool needsRefreshToken(); + public: /** This constructor uses OAuth code flow to get tokens. */ GoogleDriveStorage(Common::String code); @@ -106,12 +106,6 @@ public: virtual Common::String getRootDirectoryId(); - /** - * Gets new access_token. Pass a callback, so you could - * continue your work when new token is available. - */ - void refreshAccessToken(BoolCallback callback, Networking::ErrorCallback errorCallback = nullptr); - Common::String accessToken() const { return _token; } }; |