mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-24 03:24:50 +00:00
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:
parent
60504dce75
commit
e8669f693c
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user