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