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

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