[shotwell/wip/pluggable-auth: 13/20] WIP



commit 79923bdeaf4b007d7c422e241a3663ecda53bd63
Author: Jens Georg <mail jensge org>
Date:   Mon Feb 6 19:08:31 2017 +0100

    WIP

 Makefile.am                                        |    3 +
 authenticator.am                                   |   29 ++++++++++
 configure.ac                                       |   28 ++++++++++
 .../shotwell}/FacebookPublishingAuthenticator.vala |   13 +++--
 .../shotwell}/FlickrPublishingAuthenticator.vala   |   55 +++++++++++++++++++-
 .../shotwell/ShotwellAuthenticatorFactory.vala     |   33 ++++++++++++
 .../shotwell-publishing/FacebookPublishing.vala    |    4 +-
 plugins/shotwell-publishing/FlickrPublishing.vala  |    4 +-
 publish.am                                         |   11 ++--
 src/plugins/PublishingInterfaces.vala              |    7 ++-
 10 files changed, 171 insertions(+), 16 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 4568e29..93b929b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -131,6 +131,9 @@ include $(top_srcdir)/common.am
 include $(top_srcdir)/shotwell.am
 include $(top_srcdir)/thumbnailer.am
 
+# Authenticators
+include $(top_srcdir)/authenticator.am
+
 # Plugins
 include $(top_srcdir)/publish.am
 
diff --git a/authenticator.am b/authenticator.am
new file mode 100644
index 0000000..a0c9b37
--- /dev/null
+++ b/authenticator.am
@@ -0,0 +1,29 @@
+lib_LTLIBRARIES += plugins/authenticator/libshotwell-authenticator.la
+plugins_authenticator_libshotwell_authenticator_la_SOURCES = \
+       $(abs_top_srcdir)/plugins/shotwell-plugin-common.vapi
+
+plugins_authenticator_libshotwell_authenticator_la_VALAFLAGS = \
+       $(COMMON_VALAFLAGS) \
+       --library shotwell-authenticator \
+       --vapi=plugins/authenticator/shotwell-authenticator.vapi \
+       --header=plugins/authenticator/shotwell-authenticator.h \
+       --pkg shotwell-plugin-dev-1.0 \
+       $(AUTHENTICATOR_PACKAGES) \
+       --vapidir $(abs_top_srcdir)/plugins
+
+plugins_authenticator_libshotwell_authenticator_la_LIBADD = \
+       $(AUTHENTICATOR_LIBS) \
+       $(top_builddir)/plugins/common/libshotwell-plugin-common.la
+
+plugins_authenticator_libshotwell_authenticator_la_CFLAGS = \
+       $(COMMON_CFLAGS) \
+       $(AUTHENTICATOR_CFLAGS) \
+       -I $(top_srcdir)/plugins \
+       -DPLUGIN_RESOURCE_PATH='"/org/gnome/Shotwell/Authenticator"'
+
+if AUTHENTICATOR_SHOTWELL
+plugins_authenticator_libshotwell_authenticator_la_SOURCES += \
+       plugins/authenticator/shotwell/ShotwellAuthenticatorFactory.vala \
+       plugins/authenticator/shotwell/FacebookPublishingAuthenticator.vala \
+       plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
+endif
diff --git a/configure.ac b/configure.ac
index 28720b0..c67fb7a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -81,6 +81,25 @@ VALAFLAGS="-g"
 AC_SUBST([VALAFLAGS])
 
 dnl ***********************************************************************
+dnl Check for authenticator
+dnl ***********************************************************************
+AC_ARG_WITH([authenticator],
+            AS_HELP_STRING([--with-authenticator=@<:@shotwell,goa,uoa@:>@]
+                           [Which authentication back-end to use (defaul: shotwell)]),
+                           [with_authenticator=$withval],
+                           [with_authenticator=shotwell])
+AS_IF([test "x$with_authenticator" != "xshotwell" &&
+       test "x$with_authenticator" != "xgoa" &&
+       test "x$with_authenticator" != "xuoa"],
+            [AC_MSG_NOTICE([Unknown authenticator $[]with_authenticator, using shotwell])
+             with_authenticator="shotwell"
+            ])
+
+AM_CONDITIONAL([AUTHENTICATOR_SHOTWELL],[test "x$with_authenticator" = "xshotwell"])
+AM_CONDITIONAL([AUTHENTICATOR_GOA],[test "x$with_authenticator" = "xgoa"])
+AM_CONDITIONAL([AUTHENTICATOR_UOA],[test "x$with_authenticator" = "xuoa"])
+
+dnl ***********************************************************************
 dnl Check for required packages
 dnl ***********************************************************************
 PKG_CHECK_MODULES(SHOTWELL, [
@@ -118,6 +137,14 @@ PKG_CHECK_MODULES(PUBLISHING, [gobject-2.0 glib-2.0 gexiv2 json-glib-1.0
 PKG_CHECK_MODULES(TRANSITIONS, [gobject-2.0 cairo gio-2.0 gdk-pixbuf-2.0
                                 gdk-3.0])
 
+AS_IF([test "x$with_authenticator" = "xshotwell"],
+      [
+        PKG_CHECK_MODULES(AUTHENTICATOR, [gobject-2.0 glib-2.0 libsoup-2.4
+                                          webkit2gtk-4.0 gee-0.8 gtk+-3.0
+                                          libxml-2.0])
+        AC_SUBST(AUTHENTICATOR_PACKAGES, ["--pkg webkit2gtk-4.0 --pkg gtk+-3.0 --pkg libsoup-2.4 --pkg 
gee-0.8 --pkg libxml-2.0"])
+      ])
+
 dnl ***********************************************************************
 dnl Unity support
 dnl ***********************************************************************
@@ -199,4 +226,5 @@ echo "  Prefix ............................... : ${prefix}"
 echo "  Libdir ............................... : ${libdir}"
 echo "  Unity support ........................ : ${HAVE_UNITY}"
 echo "  Additional publishing plugins ........ : ${HAVE_EXTRA_PLUGINS}"
+echo "  Authentication library ................: ${with_authenticator}"
 echo ""
diff --git a/plugins/shotwell-publishing/FacebookPublishingAuthenticator.vala 
b/plugins/authenticator/shotwell/FacebookPublishingAuthenticator.vala
similarity index 96%
rename from plugins/shotwell-publishing/FacebookPublishingAuthenticator.vala
rename to plugins/authenticator/shotwell/FacebookPublishingAuthenticator.vala
index ba9c6a7..4aa4fa4 100644
--- a/plugins/shotwell-publishing/FacebookPublishingAuthenticator.vala
+++ b/plugins/authenticator/shotwell/FacebookPublishingAuthenticator.vala
@@ -4,10 +4,13 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
-namespace Publishing.Facebook {
+using Shotwell;
+using Shotwell.Plugins;
+
+namespace Publishing.Authenticator.Shotwell.Facebook {
     private const string APPLICATION_ID = "1612018629063184";
 
-    private class WebAuthenticationPane : Shotwell.Plugins.Common.WebAuthenticationPane {
+    private class WebAuthenticationPane : Common.WebAuthenticationPane {
         private static bool cache_dirty = false;
 
         public signal void login_succeeded(string success_url);
@@ -154,9 +157,9 @@ namespace Publishing.Facebook {
         }
     }
 
-    public class FacebookAuthenticator : Spit.Publishing.Authenticator, GLib.Object {
+    internal class Facebook : Spit.Publishing.Authenticator, GLib.Object {
         private Spit.Publishing.PluginHost host;
-        private Publishing.Facebook.WebAuthenticationPane web_auth_pane = null;
+        private Publishing.Authenticator.Shotwell.Facebook.WebAuthenticationPane web_auth_pane = null;
         private GLib.HashTable<string, Variant> params;
 
         private const string SERVICE_WELCOME_MESSAGE =
@@ -165,7 +168,7 @@ namespace Publishing.Facebook {
     _("You have already logged in and out of Facebook during this Shotwell session.\nTo continue publishing 
to Facebook, quit and restart Shotwell, then try publishing again.");
 
         /* Interface functions */
-        public FacebookAuthenticator(Spit.Publishing.PluginHost host) {
+        public Facebook(Spit.Publishing.PluginHost host) {
             this.host = host;
             this.params = new GLib.HashTable<string, Variant>(str_hash, str_equal);
         }
diff --git a/plugins/shotwell-publishing/FlickrPublishingAuthenticator.vala 
b/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
similarity index 89%
rename from plugins/shotwell-publishing/FlickrPublishingAuthenticator.vala
rename to plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
index 1bf930b..2289a3e 100644
--- a/plugins/shotwell-publishing/FlickrPublishingAuthenticator.vala
+++ b/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
@@ -4,7 +4,58 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
-namespace Publishing.Authenticator {
+namespace Publishing.Flickr {
+    internal class Transaction : Publishing.RESTSupport.Transaction {
+        public Transaction() {
+            var foo = null as Publishing.RESTSupport.Session;
+
+            base(foo, Publishing.RESTSupport.HttpMethod.POST);
+        }
+
+        public Transaction.with_uri (Publishing.RESTSupport.Session session,
+                                     string uri,
+                                     Publishing.RESTSupport.HttpMethod method) {
+            base.with_endpoint_url(session, uri, method);
+        }
+    }
+
+    internal class Session : Publishing.RESTSupport.Session {
+        public override bool is_authenticated() {
+            return false;
+        }
+
+        public void set_api_credentials(string key, string secret) {
+        }
+
+        public string get_request_phase_token() {
+            return "";
+        }
+
+        public string get_request_phase_token_secret() {
+            return "";
+        }
+
+        public string get_access_phase_token() {
+            return "";
+        }
+
+        public string get_access_phase_token_secret() {
+            return "";
+        }
+
+        public string get_username() {
+            return "";
+        }
+
+        public void set_request_phase_credentials (string token, string token_secret) {
+        }
+
+        public void set_access_phase_credentials(string token, string token_secret, string user_name) {
+        }
+    }
+}
+
+namespace Publishing.Authenticator.Shotwell.Flickr {
     internal const string API_KEY = "60dd96d4a2ad04888b09c9e18d82c26f";
     internal const string API_SECRET = "d0960565e03547c1";
 
@@ -82,7 +133,7 @@ namespace Publishing.Authenticator {
     }
 
 
-    public class Flickr : GLib.Object, Spit.Publishing.Authenticator {
+    internal class Flickr : GLib.Object, Spit.Publishing.Authenticator {
         private GLib.HashTable<string, Variant> params;
         private Publishing.Flickr.Session session;
         private Spit.Publishing.PluginHost host;
diff --git a/plugins/authenticator/shotwell/ShotwellAuthenticatorFactory.vala 
b/plugins/authenticator/shotwell/ShotwellAuthenticatorFactory.vala
new file mode 100644
index 0000000..d804440
--- /dev/null
+++ b/plugins/authenticator/shotwell/ShotwellAuthenticatorFactory.vala
@@ -0,0 +1,33 @@
+namespace Publishing.Authenticator {
+    public class Factory : Spit.Publishing.AuthenticatorFactory, Object {
+        private static Factory instance = null;
+
+        public static Factory get_instance() {
+            if (Factory.instance == null) {
+                Factory.instance = new Factory();
+            }
+
+            return Factory.instance;
+        }
+
+        public GLib.List<string> get_available_authenticators() {
+            var list = new GLib.List<string>();
+            list.append ("flickr");
+            list.append ("facebook");
+
+            return list;
+        }
+
+        public Spit.Publishing.Authenticator? create(string provider,
+                                                     Spit.Publishing.PluginHost host) {
+            switch (provider) {
+                case "flickr":
+                    return new Shotwell.Flickr.Flickr(host);
+                case "facebook":
+                    return new Shotwell.Facebook.Facebook(host);
+                default:
+                    return null;
+            }
+        }
+    }
+}
diff --git a/plugins/shotwell-publishing/FacebookPublishing.vala 
b/plugins/shotwell-publishing/FacebookPublishing.vala
index f6f4032..e61db22 100644
--- a/plugins/shotwell-publishing/FacebookPublishing.vala
+++ b/plugins/shotwell-publishing/FacebookPublishing.vala
@@ -186,7 +186,9 @@ public class FacebookPublisher : Spit.Publishing.Publisher, GLib.Object {
         this.host = host;
 
         this.publishing_params = new PublishingParameters();
-        this.authenticator = new Publishing.Facebook.FacebookAuthenticator(host);
+        this.authenticator =
+            Publishing.Authenticator.Factory.get_instance().create("facebook",
+                    host);
 
         this.graph_session = new GraphSession();
         graph_session.authenticated.connect(on_session_authenticated);
diff --git a/plugins/shotwell-publishing/FlickrPublishing.vala 
b/plugins/shotwell-publishing/FlickrPublishing.vala
index 7478778..09b655c 100644
--- a/plugins/shotwell-publishing/FlickrPublishing.vala
+++ b/plugins/shotwell-publishing/FlickrPublishing.vala
@@ -98,7 +98,7 @@ public class FlickrPublisher : Spit.Publishing.Publisher, GLib.Object {
     private bool was_started = false;
     private Session session = null;
     private PublishingOptionsPane publishing_options_pane = null;
-    private Publishing.Authenticator.Flickr authenticator;
+    private Spit.Publishing.Authenticator authenticator = null;
    
     private PublishingParameters parameters = null;
 
@@ -109,7 +109,7 @@ public class FlickrPublisher : Spit.Publishing.Publisher, GLib.Object {
         this.host = host;
         this.session = new Session();
         this.parameters = new PublishingParameters();
-        this.authenticator = new Publishing.Authenticator.Flickr (host);
+        this.authenticator = Publishing.Authenticator.Factory.get_instance().create("flickr", host);
 
         this.authenticator.authenticated.connect(on_session_authenticated);
     }
diff --git a/publish.am b/publish.am
index a5c2d87..7762900 100644
--- a/publish.am
+++ b/publish.am
@@ -19,13 +19,12 @@ dist_noinst_DATA += \
 plugins_shotwell_publishing_shotwell_publishing_la_SOURCES = \
        plugins/shotwell-publishing/shotwell-publishing.vala \
        plugins/shotwell-publishing/FacebookPublishing.vala \
-       plugins/shotwell-publishing/FacebookPublishingAuthenticator.vala \
        plugins/shotwell-publishing/PicasaPublishing.vala \
        plugins/shotwell-publishing/FlickrPublishing.vala \
-       plugins/shotwell-publishing/FlickrPublishingAuthenticator.vala \
        plugins/shotwell-publishing/YouTubePublishing.vala \
        plugins/shotwell-publishing/PiwigoPublishing.vala \
-       plugins/shotwell-plugin-common.vapi
+       plugins/shotwell-plugin-common.vapi \
+       plugins/authenticator/shotwell-authenticator.vapi
 
 nodist_plugins_shotwell_publishing_shotwell_publishing_la_SOURCES = \
        plugins/shotwell-publishing/resource.c
@@ -63,11 +62,13 @@ plugins_shotwell_publishing_shotwell_publishing_la_CFLAGS = \
        $(COMMON_CFLAGS) \
        -DGCR_API_SUBJECT_TO_CHANGE \
        $(PUBLISHING_CFLAGS) \
-       -I $(top_srcdir)/plugins
+       -I $(top_srcdir)/plugins \
+       -I $(top_srcdir)/plugins/authenticator
 
 plugins_shotwell_publishing_shotwell_publishing_la_LDFLAGS = \
        $(SHOTWELL_PLUGIN_LDFLAGS)
 
 plugins_shotwell_publishing_shotwell_publishing_la_LIBADD = \
        $(PUBLISHING_LIBS) \
-       $(top_builddir)/plugins/common/libshotwell-plugin-common.la
+       $(top_builddir)/plugins/common/libshotwell-plugin-common.la \
+       $(top_builddir)/plugins/authenticator/libshotwell-authenticator.la
diff --git a/src/plugins/PublishingInterfaces.vala b/src/plugins/PublishingInterfaces.vala
index 7695bab..3015452 100644
--- a/src/plugins/PublishingInterfaces.vala
+++ b/src/plugins/PublishingInterfaces.vala
@@ -621,8 +621,13 @@ public interface Authenticator : Object {
 }
 
 public interface AuthenticatorFactory : Object {
+    // By contract, every AuthenticatorFactory implementation needs to have a
+    // static get_instance() method. Unfortunately this is not expressable in
+    // Vala.
+
     public abstract GLib.List<string> get_available_authenticators();
-    public abstract Authenticator? create(string provider);
+    public abstract Authenticator? create(string provider,
+            Spit.Publishing.PluginHost host);
 }
 
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]