diff options
-rw-r--r-- | backends/cloud/dropbox/dropboxstorage.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index 789f6b497c..d12070316b 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -92,25 +92,34 @@ void DropboxStorage::getAccessToken(Common::String code) { void DropboxStorage::codeFlowComplete(Networking::JsonResponse response) { Common::JSONValue *json = (Common::JSONValue *)response.value; - if (json) { - Common::JSONObject result = json->asObject(); - if (!result.contains("access_token") || !result.contains("uid")) { - warning("DropboxStorage: bad response, no token/uid passed"); - debug(9, "%s", json->stringify(true).c_str()); - CloudMan.removeStorage(this); - } else { - _token = result.getVal("access_token")->asString(); - _uid = result.getVal("uid")->asString(); - ConfMan.removeKey("dropbox_code", ConfMan.kCloudDomain); - CloudMan.replaceStorage(this, kStorageDropboxId); - ConfMan.flushToDisk(); - } + if (json == nullptr) { + debug(9, "DropboxStorage::codeFlowComplete: got NULL instead of JSON!"); + CloudMan.removeStorage(this); + return; + } + if (!json->isObject()) { + debug(9, "DropboxStorage::codeFlowComplete: Passed JSON is not an object!"); + CloudMan.removeStorage(this); delete json; - } else { - debug(9, "DropboxStorage::codeFlowComplete: got NULL instead of JSON!"); + return; + } + + Common::JSONObject result = json->asObject(); + if (!Networking::CurlJsonRequest::jsonContainsString(result, "access_token", "DropboxStorage::codeFlowComplete") || + !Networking::CurlJsonRequest::jsonContainsString(result, "uid", "DropboxStorage::codeFlowComplete")) { + warning("DropboxStorage: bad response, no token/uid passed"); + debug(9, "%s", json->stringify(true).c_str()); CloudMan.removeStorage(this); + } else { + _token = result.getVal("access_token")->asString(); + _uid = result.getVal("uid")->asString(); + ConfMan.removeKey("dropbox_code", ConfMan.kCloudDomain); + CloudMan.replaceStorage(this, kStorageDropboxId); + ConfMan.flushToDisk(); } + + delete json; } void DropboxStorage::codeFlowFailed(Networking::ErrorResponse error) { |