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/box | |
| 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/box')
| -rw-r--r-- | backends/cloud/box/boxstorage.cpp | 52 | ||||
| -rw-r--r-- | backends/cloud/box/boxstorage.h | 10 |
2 files changed, 3 insertions, 59 deletions
diff --git a/backends/cloud/box/boxstorage.cpp b/backends/cloud/box/boxstorage.cpp index d743e9546e..42e902902d 100644 --- a/backends/cloud/box/boxstorage.cpp +++ b/backends/cloud/box/boxstorage.cpp @@ -55,57 +55,7 @@ Common::String BoxStorage::cloudProvider() { return "box"; } uint32 BoxStorage::storageIndex() { return kStorageBoxId; } -void BoxStorage::refreshAccessToken(BoolCallback callback, Networking::ErrorCallback errorCallback) { - if (_refreshToken == "") { - warning("BoxStorage: no refresh token available to get new access token."); - if (callback) (*callback)(BoolResponse(nullptr, false)); - return; - } - - Networking::JsonCallback innerCallback = new Common::CallbackBridge<BoxStorage, BoolResponse, Networking::JsonResponse>(this, &BoxStorage::tokenRefreshed, callback); - if (errorCallback == nullptr) - errorCallback = getErrorPrintingCallback(); - - Common::String url = "https://cloud.scummvm.org/box/refresh/" + _refreshToken; // TODO: subject to change - Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(innerCallback, errorCallback, url); - addRequest(request); -} - -void BoxStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResponse response) { - Common::JSONValue *json = response.value; - if (!json) { - warning("BoxStorage: got NULL instead of JSON"); - if (callback) - (*callback)(BoolResponse(nullptr, false)); - delete callback; - return; - } - - if (!Networking::CurlJsonRequest::jsonIsObject(json, "BoxStorage")) { - if (callback) - (*callback)(BoolResponse(nullptr, false)); - delete json; - delete callback; - return; - } - - Common::JSONObject result = json->asObject(); - if (!Networking::CurlJsonRequest::jsonContainsString(result, "access_token", "BoxStorage") || - !Networking::CurlJsonRequest::jsonContainsString(result, "refresh_token", "BoxStorage")) { - warning("BoxStorage: 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(); - _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 BoxStorage::needsRefreshToken() { return true; } void BoxStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain); diff --git a/backends/cloud/box/boxstorage.h b/backends/cloud/box/boxstorage.h index e22624a20c..a6ceb522ad 100644 --- a/backends/cloud/box/boxstorage.h +++ b/backends/cloud/box/boxstorage.h @@ -33,8 +33,6 @@ class BoxStorage: public Id::IdStorage { /** This private constructor is called from loadFromConfig(). */ BoxStorage(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); @@ -51,6 +49,8 @@ protected: */ virtual uint32 storageIndex(); + virtual bool needsRefreshToken(); + public: /** This constructor uses OAuth code flow to get tokens. */ BoxStorage(Common::String code); @@ -104,12 +104,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; } }; |
