(auth): Add proxy authentication WebView for server login
This commit is contained in:
@@ -4,6 +4,7 @@ import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.webkit.CookieManager
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
|
||||
@@ -35,6 +36,41 @@ class MainActivity : FlutterActivity() {
|
||||
|
||||
methodChannel = io.flutter.plugin.common.MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
|
||||
|
||||
// Setup cookie manager channel for WebView cookie access
|
||||
val cookieChannel = io.flutter.plugin.common.MethodChannel(
|
||||
flutterEngine.dartExecutor.binaryMessenger,
|
||||
"com.conduit.app/cookies"
|
||||
)
|
||||
|
||||
cookieChannel.setMethodCallHandler { call, result ->
|
||||
if (call.method == "getCookies") {
|
||||
val url = call.argument<String>("url")
|
||||
if (url == null) {
|
||||
result.error("INVALID_ARGS", "Invalid URL", null)
|
||||
return@setMethodCallHandler
|
||||
}
|
||||
|
||||
// Get cookies from Android's CookieManager (shared with WebView)
|
||||
val cookieManager = CookieManager.getInstance()
|
||||
val cookieString = cookieManager.getCookie(url)
|
||||
|
||||
val cookieMap = mutableMapOf<String, String>()
|
||||
if (cookieString != null) {
|
||||
// Parse cookie string: "name1=value1; name2=value2"
|
||||
cookieString.split(";").forEach { cookie ->
|
||||
val parts = cookie.trim().split("=", limit = 2)
|
||||
if (parts.size == 2) {
|
||||
cookieMap[parts[0].trim()] = parts[1].trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.success(cookieMap)
|
||||
} else {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
// Check if started with context
|
||||
handleIntent(intent)
|
||||
}
|
||||
|
||||
@@ -14,3 +14,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,3 +12,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,3 +12,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
android:pathData="M7,18h2V6H7v12zM11,22h2V2h-2v20zM3,14h2v-4H3v4zM15,18h2V6h-2v12zM19,10v4h2v-4h-2z" />
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
@@ -7,3 +7,4 @@
|
||||
</shape>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,3 +10,4 @@
|
||||
</item>
|
||||
</ripple>
|
||||
|
||||
|
||||
|
||||
@@ -10,3 +10,4 @@
|
||||
</ripple>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
</ripple>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
</ripple>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
</ripple>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,3 +12,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,3 +14,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,3 +12,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,3 +12,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
android:pathData="M7,18h2V6H7v12zM11,22h2V2h-2v20zM3,14h2v-4H3v4zM15,18h2V6h-2v12zM19,10v4h2v-4h-2z" />
|
||||
</vector>
|
||||
|
||||
|
||||
|
||||
@@ -7,3 +7,4 @@
|
||||
</shape>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,3 +10,4 @@
|
||||
</item>
|
||||
</ripple>
|
||||
|
||||
|
||||
|
||||
@@ -10,3 +10,4 @@
|
||||
</ripple>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
</ripple>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
</ripple>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
</ripple>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,3 +53,4 @@
|
||||
</layer-list>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -129,3 +129,4 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
@@ -30,3 +30,4 @@
|
||||
</resources>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,3 +9,4 @@
|
||||
</resources>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,3 +30,4 @@
|
||||
</resources>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,3 +9,4 @@
|
||||
</resources>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,3 +13,4 @@
|
||||
</resources>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -17,3 +17,4 @@
|
||||
android:widgetFeatures="reconfigurable" />
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user