CLOUD: Update BaseStorage to expect no refresh_token

While refreshing access_token, some cloud providers also pass a new
refresh_token. Google Drive does not, and accepts the same refresh_token
next time. These changes allow this to happen.
This commit is contained in:
Alexander Tkachev 2019-07-16 14:09:38 +07:00 committed by Matan Bareket
parent 60504dce75
commit e8669f693c
10 changed files with 25 additions and 2 deletions

View File

@ -101,7 +101,7 @@ void BaseStorage::codeFlowComplete(Networking::JsonResponse response) {
return;
}
debug(9, "%s", json->stringify(true).c_str()); // TODO: remove before commit
debug(9, "%s", json->stringify(true).c_str()); // TODO: remove when done testing against cloud.scummvm.org
_token = oauth.getVal("access_token")->asString();
if (requiresRefreshToken) {
_refreshToken = oauth.getVal("refresh_token")->asString();
@ -188,7 +188,7 @@ void BaseStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResponse
}
Common::JSONObject oauth = result.getVal("oauth")->asObject();
bool requiresRefreshToken = needsRefreshToken(); // TODO: it seems Google Drive might not send new refresh token, and still accept old one
bool requiresRefreshToken = !canReuseRefreshToken();
if (!Networking::CurlJsonRequest::jsonContainsString(oauth, "access_token", "BaseStorage::tokenRefreshed") ||
!Networking::CurlJsonRequest::jsonContainsString(oauth, "refresh_token", "BaseStorage::tokenRefreshed", !requiresRefreshToken)) {
warning("BaseStorage: bad response, no 'access_token' or 'refresh_token' attribute passed");
@ -200,6 +200,8 @@ void BaseStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResponse
return;
}
debug(9, "%s", json->stringify(true).c_str()); // TODO: remove when done testing against cloud.scummvm.org
_token = oauth.getVal("access_token")->asString();
if (requiresRefreshToken) {
_refreshToken = oauth.getVal("refresh_token")->asString();

View File

@ -69,6 +69,11 @@ protected:
*/
virtual bool needsRefreshToken() = 0;
/**
* Return whether to expect new refresh_token on refresh.
*/
virtual bool canReuseRefreshToken() = 0;
private:
void tokenRefreshed(BoolCallback callback, Networking::JsonResponse response);

View File

@ -57,6 +57,8 @@ uint32 BoxStorage::storageIndex() { return kStorageBoxId; }
bool BoxStorage::needsRefreshToken() { return true; }
bool BoxStorage::canReuseRefreshToken() { return false; }
void BoxStorage::saveConfig(Common::String keyPrefix) {
ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain);
ConfMan.set(keyPrefix + "refresh_token", _refreshToken, ConfMan.kCloudDomain);

View File

@ -51,6 +51,8 @@ protected:
virtual bool needsRefreshToken();
virtual bool canReuseRefreshToken();
public:
/** This constructor uses OAuth code flow to get tokens. */
BoxStorage(Common::String code);

View File

@ -54,6 +54,8 @@ uint32 DropboxStorage::storageIndex() { return kStorageDropboxId; }
bool DropboxStorage::needsRefreshToken() { return false; }
bool DropboxStorage::canReuseRefreshToken() { return false; }
void DropboxStorage::saveConfig(Common::String keyPrefix) {
ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain);
}

View File

@ -47,6 +47,8 @@ protected:
virtual bool needsRefreshToken();
virtual bool canReuseRefreshToken();
public:
/** This constructor uses OAuth code flow to get tokens. */
DropboxStorage(Common::String code);

View File

@ -58,6 +58,8 @@ uint32 GoogleDriveStorage::storageIndex() { return kStorageGoogleDriveId; }
bool GoogleDriveStorage::needsRefreshToken() { return true; }
bool GoogleDriveStorage::canReuseRefreshToken() { return true; }
void GoogleDriveStorage::saveConfig(Common::String keyPrefix) {
ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain);
ConfMan.set(keyPrefix + "refresh_token", _refreshToken, ConfMan.kCloudDomain);

View File

@ -54,6 +54,8 @@ protected:
virtual bool needsRefreshToken();
virtual bool canReuseRefreshToken();
public:
/** This constructor uses OAuth code flow to get tokens. */
GoogleDriveStorage(Common::String code);

View File

@ -57,6 +57,8 @@ uint32 OneDriveStorage::storageIndex() { return kStorageOneDriveId; }
bool OneDriveStorage::needsRefreshToken() { return true; }
bool OneDriveStorage::canReuseRefreshToken() { return false; }
void OneDriveStorage::saveConfig(Common::String keyPrefix) {
ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain);
ConfMan.set(keyPrefix + "refresh_token", _refreshToken, ConfMan.kCloudDomain);

View File

@ -51,6 +51,8 @@ protected:
virtual bool needsRefreshToken();
virtual bool canReuseRefreshToken();
public:
/** This constructor uses OAuth code flow to get tokens. */
OneDriveStorage(Common::String code);