Loading app/src/main/java/foundation/e/apps/feature/auth/login/GoogleOAuthCredentialsExtractor.kt +7 −0 Original line number Diff line number Diff line Loading @@ -17,9 +17,16 @@ package foundation.e.apps.feature.auth.login import java.net.URI internal object GoogleOAuthCredentialsExtractor { const val EMBEDDED_SETUP_URL = "https://accounts.google.com/EmbeddedSetup" private const val AUTH_TOKEN_COOKIE = "oauth_token" private val ALLOWED_HOSTS = setOfNotNull(URI(EMBEDDED_SETUP_URL).host) fun isAllowedHost(host: String?): Boolean { return host != null && host in ALLOWED_HOSTS } fun extractOauthToken(cookieHeader: String?): String? { if (cookieHeader.isNullOrBlank()) { Loading app/src/main/java/foundation/e/apps/feature/auth/login/component/GoogleOAuthWebView.kt +5 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.viewinterop.AndroidView import androidx.core.net.toUri import foundation.e.apps.feature.auth.login.GoogleOAuthCredentialsExtractor import foundation.e.apps.feature.auth.login.LoginOauthToken Loading Loading @@ -106,7 +107,6 @@ private fun WebView.configureGoogleOAuthWebView( cookieManager.acceptThirdPartyCookies(this) cookieManager.setAcceptThirdPartyCookies(this, true) settings.safeBrowsingEnabled = false settings.apply { allowContentAccess = true cacheMode = WebSettings.LOAD_DEFAULT Loading @@ -116,6 +116,10 @@ private fun WebView.configureGoogleOAuthWebView( webViewClient = object : WebViewClient() { override fun onPageFinished(view: WebView, url: String) { if (!GoogleOAuthCredentialsExtractor.isAllowedHost(url.toUri().host)) { return } val oauthToken = GoogleOAuthCredentialsExtractor.extractOauthToken( CookieManager.getInstance().getCookie(url), ) Loading Loading
app/src/main/java/foundation/e/apps/feature/auth/login/GoogleOAuthCredentialsExtractor.kt +7 −0 Original line number Diff line number Diff line Loading @@ -17,9 +17,16 @@ package foundation.e.apps.feature.auth.login import java.net.URI internal object GoogleOAuthCredentialsExtractor { const val EMBEDDED_SETUP_URL = "https://accounts.google.com/EmbeddedSetup" private const val AUTH_TOKEN_COOKIE = "oauth_token" private val ALLOWED_HOSTS = setOfNotNull(URI(EMBEDDED_SETUP_URL).host) fun isAllowedHost(host: String?): Boolean { return host != null && host in ALLOWED_HOSTS } fun extractOauthToken(cookieHeader: String?): String? { if (cookieHeader.isNullOrBlank()) { Loading
app/src/main/java/foundation/e/apps/feature/auth/login/component/GoogleOAuthWebView.kt +5 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.viewinterop.AndroidView import androidx.core.net.toUri import foundation.e.apps.feature.auth.login.GoogleOAuthCredentialsExtractor import foundation.e.apps.feature.auth.login.LoginOauthToken Loading Loading @@ -106,7 +107,6 @@ private fun WebView.configureGoogleOAuthWebView( cookieManager.acceptThirdPartyCookies(this) cookieManager.setAcceptThirdPartyCookies(this, true) settings.safeBrowsingEnabled = false settings.apply { allowContentAccess = true cacheMode = WebSettings.LOAD_DEFAULT Loading @@ -116,6 +116,10 @@ private fun WebView.configureGoogleOAuthWebView( webViewClient = object : WebViewClient() { override fun onPageFinished(view: WebView, url: String) { if (!GoogleOAuthCredentialsExtractor.isAllowedHost(url.toUri().host)) { return } val oauthToken = GoogleOAuthCredentialsExtractor.extractOauthToken( CookieManager.getInstance().getCookie(url), ) Loading