[shotwell/wip/uoa: 2/2] wip: Import files from ubuntu package



commit a5d6914faf15ba85dabb439901e8d73528d33577
Author: Jens Georg <mail jensge org>
Date:   Sat Mar 25 19:46:54 2017 +0100

    wip: Import files from ubuntu package
    
    Signed-off-by: Jens Georg <mail jensge org>

 authenticator.am                                   |    9 +
 misc/shotwell-sharing-facebook.service             |   13 ++
 misc/shotwell-sharing-flickr.service               |    7 +
 misc/shotwell-sharing-picasa.service               |   22 +++
 .../authenticator/uoa/UOAAuthenticatorFactory.vala |   38 ++++
 plugins/authenticator/uoa/accounts.vala            |  200 ++++++++++++++++++++
 6 files changed, 289 insertions(+), 0 deletions(-)
---
diff --git a/authenticator.am b/authenticator.am
index abc0fa3..bcb5260 100644
--- a/authenticator.am
+++ b/authenticator.am
@@ -56,3 +56,12 @@ plugins_authenticator_libshotwell_authenticator_la_SOURCES += \
        plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala \
        plugins/authenticator/shotwell/GoogleAuthenticator.vala
 endif
+
+if AUTHENTICATOR_UOA
+AUTHENTICATOR_RESOURCE_FILE := 
$(abs_top_srcdir)/plugins/authenticator/uoa/org.gnome.Shotwell.Authenticator.gresource.xml
+AUTHENTICATOR_RESOURCE_SOURCEDIR := $(abs_top_srcdir)/plugins/authenticator/uoa
+
+plugins_authenticator_libshotwell_authenticator_la_SOURCES += \
+       plugins/authenticator/uoa/UOAAuthenticatorFactory.vala \
+       plugins/authenticator/uoa/accounts.vala
+endif
diff --git a/misc/shotwell-sharing-facebook.service b/misc/shotwell-sharing-facebook.service
new file mode 100644
index 0000000..ef2f61a
--- /dev/null
+++ b/misc/shotwell-sharing-facebook.service
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<service id="shotwell-sharing-facebook">
+  <type>shotwell-sharing</type>
+  <name>Facebook</name>
+  <icon>facebook</icon>
+  <provider>facebook</provider>
+  <template>
+    <group name="auth/oauth2/user_agent">
+      <setting type="as" name="Scope">['publish_actions','user_photos','user_videos']</setting>
+      <setting name="ClientId">1612018629063184</setting>
+    </group>
+  </template>
+</service>
diff --git a/misc/shotwell-sharing-flickr.service b/misc/shotwell-sharing-flickr.service
new file mode 100644
index 0000000..92c038a
--- /dev/null
+++ b/misc/shotwell-sharing-flickr.service
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<service id="shotwell-sharing-flickr">
+  <type>shotwell-sharing</type>
+  <name>Flickr</name>
+  <icon>flickr</icon>
+  <provider>flickr</provider>
+</service>
diff --git a/misc/shotwell-sharing-picasa.service b/misc/shotwell-sharing-picasa.service
new file mode 100644
index 0000000..0ed964b
--- /dev/null
+++ b/misc/shotwell-sharing-picasa.service
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<service id="shotwell-sharing-picasa">
+  <type>shotwell-sharing</type>
+  <name>Picasa</name>
+  <icon>icon_picasa</icon>
+  <provider>google</provider>
+  <template>
+    <group name="auth/oauth2">
+      <group name="user_agent">
+        <setting type="as" 
name="Scope">['http://picasaweb.google.com/data/','https://picasaweb.google.com/data/','https://www.googleapis.com/auth/userinfo.profile']</setting>
+        <setting 
name="ClientId">1073902228337-nv1s75sfvrt75lfcq4pg3pn7gee8e1d5.apps.googleusercontent.com</setting>
+        <setting name="RedirectUri">https://wiki.ubuntu.com/</setting>
+      </group>
+      <group name="web_server">
+        <setting type="as" 
name="Scope">['http://picasaweb.google.com/data/','https://picasaweb.google.com/data/','https://www.googleapis.com/auth/userinfo.profile']</setting>
+        <setting 
name="ClientId">1073902228337-nv1s75sfvrt75lfcq4pg3pn7gee8e1d5.apps.googleusercontent.com</setting>
+        <setting name="ClientSecret">jWoGL5PDGk55ZfpBYNOgG43g</setting>
+        <setting name="RedirectUri">https://wiki.ubuntu.com/</setting>
+      </group>
+    </group>
+  </template>
+</service>
diff --git a/plugins/authenticator/uoa/UOAAuthenticatorFactory.vala 
b/plugins/authenticator/uoa/UOAAuthenticatorFactory.vala
new file mode 100644
index 0000000..450b273
--- /dev/null
+++ b/plugins/authenticator/uoa/UOAAuthenticatorFactory.vala
@@ -0,0 +1,38 @@
+namespace Publishing.Authenticator {
+    public class Factory : Spit.Publishing.AuthenticatorFactory, Object {
+        private static Factory instance = null;
+        private Ag.Manager manager = null;
+        private Gee.HashSet<string> services;
+
+        public static Factory get_instance() {
+            if (Factory.instance == null) {
+                Factory.instance = new Factory();
+            }
+
+            return Factory.instance;
+        }
+
+        private Factory() {
+            this.manager = new Ag.Manager.for_service_type("shotwell-sharing");
+            this.manager.enabled_event.connect(this.on_account_enabled);
+            this.services = new Gee.ArrayList<string>();
+        }
+
+        public Gee.List<string> get_available_authenticators() {
+            return services;
+        }
+
+        public Spit.Publishing.Authenticator? create(string provider,
+                                                     Spit.Publishing.PluginHost host) {
+            return null;
+        }
+
+        private void rebuild_service_list() {
+            this.services.clear();
+
+            foreach (var account_service in this.manager.get_enabled_account_services()) {
+                services.add(account_service.get_account().get_provider_name());
+            }
+        }
+    }
+}
diff --git a/plugins/authenticator/uoa/accounts.vala b/plugins/authenticator/uoa/accounts.vala
new file mode 100644
index 0000000..abaa581
--- /dev/null
+++ b/plugins/authenticator/uoa/accounts.vala
@@ -0,0 +1,200 @@
+/* Copyright 2009-2011 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later).  See the COPYING file in this distribution.
+ */
+
+namespace Publishing.Accounts {
+
+public class SharingAccount {
+    private Ag.AccountService account_service = null;
+
+    public SharingAccount(Ag.AccountService account_service) {
+        this.account_service = account_service;
+    }
+
+    public Signon.AuthSession create_auth_session() throws GLib.Error {
+        var auth_data = account_service.get_auth_data();
+        debug("Signon-id: %u", auth_data.get_credentials_id());
+
+        return new Signon.AuthSession(auth_data.get_credentials_id(),
+                                      auth_data.get_method());
+    }
+
+    public Variant get_session_parameters(Variant? extra, out string mechanism) {
+        var auth_data = account_service.get_auth_data();
+        mechanism = auth_data.get_mechanism();
+        Variant data = auth_data.get_login_parameters(extra);
+        return data;
+    }
+}
+
+public class SharingAccounts {
+    private static Ag.Manager manager = null;
+    private string provider_name;
+    private Ag.AccountService[] all_accounts;
+
+    public SharingAccounts(string provider_name) {
+        if (manager == null) {
+            manager = new Ag.Manager.for_service_type("shotwell-sharing");
+        }
+        manager.enabled_event.connect(on_account_enabled);
+
+        this.provider_name = provider_name;
+        all_accounts = get_accounts();
+    }
+
+    private void on_account_enabled(uint account_id) {
+        /* To keep the implementation simple, just rebuild the account
+         * list from scratch */
+        all_accounts = get_accounts();
+    }
+
+    private Ag.AccountService[] get_accounts() {
+        GLib.List<Ag.AccountService> accounts =
+            manager.get_enabled_account_services();
+
+        Ag.AccountService[] list = {};
+
+        foreach (Ag.AccountService account_service in accounts) {
+            Ag.Account account = account_service.get_account();
+            if (account.get_provider_name() == provider_name) {
+                list += account_service;
+            }
+        }
+        return list;
+    }
+
+    public bool has_enabled_accounts() {
+        return all_accounts.length > 0;
+    }
+
+    public string[] list_account_names() {
+        string[] names = {};
+        foreach (Ag.AccountService account_service in all_accounts) {
+            names += account_service.get_account().get_display_name();
+        }
+        return names;
+    }
+
+    public SharingAccount? find_account(string? account_name) {
+        foreach (Ag.AccountService account_service in all_accounts)
+            if (account_service.get_account().get_display_name() == account_name) {
+                return new SharingAccount(account_service);
+            }
+
+        return null;
+    }
+}
+
+public class UOAPublisherAuthenticator : Object {
+    private weak Spit.Publishing.PluginHost host = null;
+    private Signon.AuthSession auth_session = null;
+    private SharingAccount account = null;
+    private bool firstLoginAttempt = true;
+    private bool invalidate_session = false;
+    private string welcome_message = null;
+
+    public UOAPublisherAuthenticator(SharingAccount account,
+                                     Spit.Publishing.PluginHost host,
+                                     string welcome_message)
+    {
+        this.host = host;
+        this.account = account;
+        this.welcome_message = welcome_message;
+    }
+
+    public signal void authenticated(owned Variant session_data);
+
+    public void authenticate() {
+        debug("ACTION: authentication requested.");
+
+        do_authentication();
+    }
+
+    public Variant? get_authentication_data() {
+        if (account == null) return null;
+        string mechanism = null;
+        return account.get_session_parameters(null, out mechanism);
+    }
+
+    public void invalidate_persistent_session() {
+        this.invalidate_session = true;
+    }
+
+    private void do_authentication() {
+        debug("ACTION: authenticating.");
+
+        if (account != null) {
+            try {
+                auth_session = account.create_auth_session();
+            } catch (GLib.Error e) {
+                warning("EVENT: couldn't create session for account: %s",
+                        e.message);
+            }
+        }
+
+        VariantBuilder builder = new VariantBuilder(new VariantType("a{sv}"));
+
+        if (firstLoginAttempt) {
+            firstLoginAttempt = false;
+            builder.add ("{sv}", "UiPolicy",
+                         new Variant.int32((int)Signon.SessionDataUiPolicy.NO_USER_INTERACTION));
+        } else {
+            var windowId = host.get_dialog_xid();
+            if (windowId != 0) {
+                builder.add ("{sv}", "WindowId",
+                             new Variant.uint32((uint)windowId));
+            }
+        }
+
+        if (invalidate_session) {
+            invalidate_session = false;
+            builder.add("{sv}", "ForceTokenRefresh", new Variant.boolean(true));
+        }
+
+        string mechanism = null;
+        Variant data = account.get_session_parameters(builder.end(), out mechanism);
+        if (data == null) {
+            warning ("No account authentication data");
+            host.post_error(new Spit.Publishing.PublishingError.SERVICE_ERROR(
+                "Error while accessing the account"));
+            return;
+        }
+
+        debug("Got account data");
+
+        host.set_service_locked(true);
+        auth_session.process_async.begin(data, mechanism, null,
+                                         (obj, res) => {
+            host.set_service_locked(false);
+            try {
+                Variant reply = auth_session.process_async.end(res);
+                authenticated(reply);
+            } catch (GLib.Error error) {
+                debug("got error: %s", error.message);
+                if (error is Signon.Error.USER_INTERACTION) {
+                    debug("User interaction!");
+                    do_show_service_welcome_pane();
+                } else {
+                    host.post_error(new Spit.Publishing.PublishingError.SERVICE_ERROR("Authentication 
failed"));
+                }
+            }
+        });
+    }
+
+    private void do_show_service_welcome_pane() {
+        debug("ACTION: showing service welcome pane.");
+
+        host.install_welcome_pane(welcome_message, on_service_welcome_login);
+    }
+
+    private void on_service_welcome_login() {
+        debug("EVENT: user clicked 'Login' in welcome pane.");
+
+        do_authentication();
+    }
+}
+
+}
+


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