fix: GOG sign-in starts without the previous account's web session (#1235)

This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-10-21 00:44:40 -04:00
1 parent 705da08a0e
commit 152b961940
6 files changed
+78 -18

No files matched your search

@@ -23,6 +23,14 @@ internal object LoginFlows {
override val userAgent: String get() = GogAuth.GALAXY_UA
override fun isRedirect(url: String): Boolean = url.startsWith(GogAuth.REDIRECT_PREFIX)
override fun forgetSignIn(done: () -> Unit) {
runCatching { WebCookies.expire(GogAuth.SIGN_IN_URLS, GogAuth.COOKIE_DOMAIN, listOf("/")) { done() } }
.onFailure {
Log.w(TAG, "gog: could not clear the previous web sign-in: ${it.javaClass.simpleName}")
done()
}
}
override fun finish(activity: StoreLoginActivity, view: WebView, url: String): String? {
val fragment = Uri.parse(url).fragment ?: return activity.getString(com.droiddeck.launcher.R.string.stores_login_error_verification)
val frag = Uri.parse("x://x?$fragment")
@@ -38,6 +38,7 @@ class StoreLoginActivity : ComponentActivity() {
const val EXTRA_STORE = "store"
const val EXTRA_CLIENT_URL = "client_url"
private const val KEY_STATE = "oauth_state"
private const val KEY_SIGN_IN_CLEARED = "sign_in_cleared"
@Volatile internal var floodColor: Int? = null
internal const val CHROME_UA = "Mozilla/5.0 (Linux; Android 14; SM-S918B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.103 Mobile Safari/537.36"
@@ -54,6 +55,7 @@ class StoreLoginActivity : ComponentActivity() {
fun isRedirect(url: String): Boolean
fun finish(activity: StoreLoginActivity, view: WebView, url: String): String?
val readsPage: Boolean get() = false
fun forgetSignIn(done: () -> Unit) = done()
}
private var store: Store? = null
@@ -74,6 +76,7 @@ class StoreLoginActivity : ComponentActivity() {
private var oauthState: String? = null
private val captured = AtomicBoolean(false)
private var flooded = false
private var signInCleared = false
private fun dp(value: Int): Int = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value.toFloat(), resources.displayMetrics).toInt()
@@ -109,7 +112,13 @@ class StoreLoginActivity : ComponentActivity() {
}
}
})
webView.loadUrl(flow!!.startUrl)
val start = flow!!.startUrl
signInCleared = savedInstanceState?.getBoolean(KEY_SIGN_IN_CLEARED) == true
if (signInCleared) webView.loadUrl(start)
else flow!!.forgetSignIn {
signInCleared = true
if (!isDestroyed) webView.loadUrl(start)
}
}
private fun newFlow(state: String): Flow? {
@@ -330,6 +339,7 @@ class StoreLoginActivity : ComponentActivity() {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
oauthState?.let { outState.putString(KEY_STATE, it) }
outState.putBoolean(KEY_SIGN_IN_CLEARED, signInCleared)
}
override fun onStart() {
@@ -0,0 +1,34 @@
package com.droiddeck.launcher.stores
import android.net.Uri
import android.webkit.CookieManager
internal object WebCookies {
fun expired(header: String?, domain: String, paths: List<String>, host: String? = null): List<String> {
val domains = listOfNotNull(domain, host?.takeIf { it.endsWith(domain) })
return header.orEmpty().split(';').map { it.substringBefore('=').trim() }.filter { it.isNotEmpty() }.distinct()
.flatMap { name ->
paths.flatMap { path ->
listOf("$name=; Max-Age=0; Path=$path; Secure") + domains.map { "$name=; Max-Age=0; Path=$path; Secure; Domain=$it" }
}
}
}
fun expire(urls: List<String>, domain: String, paths: List<String>, done: (Int) -> Unit) {
val cookies = CookieManager.getInstance()
val lines = urls.flatMap { url -> expired(cookies.getCookie(url), domain, paths, Uri.parse(url).host).map { url to it } }
if (lines.isEmpty()) {
done(0)
return
}
var left = lines.size
for ((url, line) in lines) {
cookies.setCookie(url, line) {
if (--left == 0) {
cookies.flush()
done(lines.size)
}
}
}
}
}
@@ -21,6 +21,7 @@ import com.droiddeck.launcher.stores.StoreInstallRoot
import com.droiddeck.launcher.stores.StoreLog
import com.droiddeck.launcher.stores.StoreLoginActivity
import com.droiddeck.launcher.stores.StoresState
import com.droiddeck.launcher.stores.WebCookies
import com.droiddeck.launcher.stores.download.DownloadEntry
import com.droiddeck.launcher.stores.download.DownloadQueue
import com.droiddeck.launcher.stores.SteamLiveShortcuts
@@ -108,28 +109,15 @@ object EpicClient {
fun forgetWebSignIn() {
android.os.Handler(android.os.Looper.getMainLooper()).post {
runCatching {
val cookies = android.webkit.CookieManager.getInstance()
var cleared = 0
for (url in COOKIE_URLS) {
val lines = expiredCookies(cookies.getCookie(url), Uri.parse(url).host)
for (line in lines) cookies.setCookie(url, line)
cleared += lines.size
WebCookies.expire(COOKIE_URLS, COOKIE_DOMAIN, COOKIE_PATHS) { cleared ->
Log.i(TAG, "cleared the Epic web sign-in ($cleared cookie lines)")
}
cookies.flush()
Log.i(TAG, "cleared the Epic web sign-in ($cleared cookie lines)")
}.onFailure { Log.w(TAG, "could not clear the Epic web sign-in: ${it.javaClass.simpleName}") }
}
}
internal fun expiredCookies(header: String?, host: String? = null): List<String> {
val domains = listOfNotNull(COOKIE_DOMAIN, host?.takeIf { it.endsWith(COOKIE_DOMAIN) })
return header.orEmpty().split(';').map { it.substringBefore('=').trim() }.filter { it.isNotEmpty() }.distinct()
.flatMap { name ->
COOKIE_PATHS.flatMap { path ->
listOf("$name=; Max-Age=0; Path=$path; Secure") + domains.map { "$name=; Max-Age=0; Path=$path; Secure; Domain=$it" }
}
}
}
internal fun expiredCookies(header: String?, host: String? = null): List<String> =
WebCookies.expired(header, COOKIE_DOMAIN, COOKIE_PATHS, host)
fun read(context: Context): Status {
val app = context.applicationContext
@@ -20,6 +20,8 @@ object GogAuth {
"&redirect_uri=https%3A%2F%2Fembed.gog.com%2Fon_login_success%3Forigin%3Dclient&response_type=token&layout=client2"
const val REDIRECT_PREFIX = "https://embed.gog.com/on_login_success"
const val GALAXY_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) GOG Galaxy/2.0"
const val COOKIE_DOMAIN = ".gog.com"
val SIGN_IN_URLS = listOf("https://login.gog.com/", "https://auth.gog.com/")
fun authUrl(state: String): String = "$AUTH_URL&state=${Uri.encode(state)}"