Blame SOURCES/0002-Add-webflow-auth-support-to-flatpak-plugin.patch

698863
From de3afc6463aeb0e2d637a0360d1b96acffdf4e6d Mon Sep 17 00:00:00 2001
698863
From: Kalev Lember <klember@redhat.com>
698863
Date: Tue, 19 May 2020 14:28:10 +0200
698863
Subject: [PATCH 2/2] Add webflow auth support to flatpak plugin
698863
698863
This is just the minimal support, launching the auth page in the default
698863
web browser when libflatpak signals that we need to do the webflow auth.
698863
698863
Possible improvements could include doing either a webkitgtk dialog, or
698863
maybe asking for confirmation before launching the web browser.
698863
---
698863
 plugins/flatpak/gs-plugin-flatpak.c | 69 +++++++++++++++++++++++++++++
698863
 1 file changed, 69 insertions(+)
698863
698863
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
698863
index 2518025d..a453cec8 100644
698863
--- a/plugins/flatpak/gs-plugin-flatpak.c
698863
+++ b/plugins/flatpak/gs-plugin-flatpak.c
698863
@@ -503,6 +503,71 @@ _basic_auth_start (FlatpakTransaction *transaction,
698863
 	gs_plugin_basic_auth_start (plugin, remote, realm, G_CALLBACK (_basic_auth_cb), data);
698863
 	return TRUE;
698863
 }
698863
+
698863
+static gboolean
698863
+_webflow_start (FlatpakTransaction *transaction,
698863
+                const char *remote,
698863
+                const char *url,
698863
+                GVariant *options,
698863
+                guint id,
698863
+                GsPlugin *plugin)
698863
+{
698863
+	const char *browser;
698863
+	g_autoptr(GError) error_local = NULL;
698863
+
698863
+	if (!gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE))
698863
+		return FALSE;
698863
+
698863
+	g_debug ("Authentication required for remote '%s'", remote);
698863
+
698863
+	/* Allow hard overrides with $BROWSER */
698863
+	browser = g_getenv ("BROWSER");
698863
+	if (browser != NULL) {
698863
+		const char *args[3] = { NULL, url, NULL };
698863
+		args[0] = browser;
698863
+		if (!g_spawn_async (NULL, (char **)args, NULL, G_SPAWN_SEARCH_PATH,
698863
+		                    NULL, NULL, NULL, &error_local)) {
698863
+			g_autoptr(GsPluginEvent) event = NULL;
698863
+
698863
+			g_warning ("Failed to start browser %s: %s", browser, error_local->message);
698863
+
698863
+			event = gs_plugin_event_new ();
698863
+			gs_flatpak_error_convert (&error_local);
698863
+			gs_plugin_event_set_error (event, error_local);
698863
+			gs_plugin_event_add_flag (event, GS_PLUGIN_EVENT_FLAG_WARNING);
698863
+			gs_plugin_report_event (plugin, event);
698863
+
698863
+			return FALSE;
698863
+		}
698863
+	} else {
698863
+		if (!g_app_info_launch_default_for_uri (url, NULL, &error_local)) {
698863
+			g_autoptr(GsPluginEvent) event = NULL;
698863
+
698863
+			g_warning ("Failed to show url: %s", error_local->message);
698863
+
698863
+			event = gs_plugin_event_new ();
698863
+			gs_flatpak_error_convert (&error_local);
698863
+			gs_plugin_event_set_error (event, error_local);
698863
+			gs_plugin_event_add_flag (event, GS_PLUGIN_EVENT_FLAG_WARNING);
698863
+			gs_plugin_report_event (plugin, event);
698863
+
698863
+			return FALSE;
698863
+		}
698863
+	}
698863
+
698863
+	g_debug ("Waiting for browser...");
698863
+
698863
+	return TRUE;
698863
+}
698863
+
698863
+static void
698863
+_webflow_done (FlatpakTransaction *transaction,
698863
+               GVariant *options,
698863
+               guint id,
698863
+               GsPlugin *plugin)
698863
+{
698863
+	g_debug ("Browser done");
698863
+}
698863
 #endif
698863
 
698863
 static FlatpakTransaction *
698863
@@ -543,6 +608,10 @@ _build_transaction (GsPlugin *plugin, GsFlatpak *flatpak,
698863
 #if FLATPAK_CHECK_VERSION(1,6,0)
698863
 	g_signal_connect (transaction, "basic-auth-start",
698863
 			  G_CALLBACK (_basic_auth_start), plugin);
698863
+	g_signal_connect (transaction, "webflow-start",
698863
+			  G_CALLBACK (_webflow_start), plugin);
698863
+	g_signal_connect (transaction, "webflow-done",
698863
+			  G_CALLBACK (_webflow_done), plugin);
698863
 #endif
698863
 
698863
 	/* use system installations as dependency sources for user installations */
698863
-- 
698863
2.26.2
698863