Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Sign-in: the renewed refresh token saved at once; the log tells why it's asked again

Rafael Abud Ferreira82fe5f98aef8
diff --git a/src/auth/auth_manager.cpp b/src/auth/auth_manager.cpp
index 3989c5a..86ed5fc 100644
--- a/src/auth/auth_manager.cpp
+++ b/src/auth/auth_manager.cpp
@@ -26,14 +26,20 @@ AuthManager::AuthManager(std::string storePath, MsaConfig cfg)
bool AuthManager::load() {
std::string text;
- if (!platform::readFile(storePath_, text)) return false;
+ if (!platform::readFile(storePath_, text)) {
+ XC_LOGI("no saved sign-in (%s)", storePath_.c_str()); // the reports tell "asked again" apart
+ return false;
+ }
auto j = json::parse(text);
if (!j) {
XC_LOGW("ignoring unreadable token store %s", storePath_.c_str());
return false;
}
// A refresh token issued to another client id is useless: start over.
- if ((*j)["clientId"].str() != msa_.config().clientId) return false;
+ if ((*j)["clientId"].str() != msa_.config().clientId) {
+ XC_LOGI("saved sign-in from another client id: asking again");
+ return false;
+ }
tokens_.refreshToken = (*j)["refreshToken"].str();
tokens_.userId = (*j)["userId"].str();
profile_.gamertag = (*j)["gamertag"].str();
@@ -231,6 +237,10 @@ bool AuthManager::signIn(xcloud::GssvClient& gssv, const DeviceCodeCallback& onC
bool networkError = false;
if (msa_.refresh(tokens_.refreshToken, t, err, {}, &networkError)) {
tokens_ = t;
+ // Microsoft hands out a new refresh token each time: saved at
+ // once, so an app closed before the Xbox sign-in ends still
+ // starts with the newest one.
+ if (!save()) XC_LOGW("the renewed sign-in could not be saved");
} else if (networkError) {
// Offline or the service is down: keep the stored account.
return false;