From 60504dce7539863a207610fd636236c7035ade3e Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 15 Jul 2019 22:14:23 +0700 Subject: CLOUD: Update storages to refresh token via cloud.scummvm.org --- backends/cloud/googledrive/googledrivestorage.cpp | 55 +---------------------- backends/cloud/googledrive/googledrivestorage.h | 10 +---- 2 files changed, 3 insertions(+), 62 deletions(-) (limited to 'backends/cloud/googledrive') 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(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; } }; -- cgit v1.2.3