[shotwell/wip/phako/libsecret: 253/254] wip



commit 64d855e9385e72ae284e1014211b64d8fa2339a5
Author: Jens Georg <mail jensge org>
Date:   Mon Aug 19 16:51:57 2019 +0200

    wip

 flatpak/org.gnome.Shotwell.json                    |  3 +-
 .../shotwell/FlickrPublishingAuthenticator.vala    |  2 +-
 .../shotwell/OAuth1Authenticator.vala              | 85 ++++++++++++++++++----
 .../shotwell/TumblrAuthenticator.vala              |  2 +-
 4 files changed, 76 insertions(+), 16 deletions(-)
---
diff --git a/flatpak/org.gnome.Shotwell.json b/flatpak/org.gnome.Shotwell.json
index 88bce896..c27f4112 100644
--- a/flatpak/org.gnome.Shotwell.json
+++ b/flatpak/org.gnome.Shotwell.json
@@ -26,7 +26,8 @@
         "--talk-name=org.freedesktop.FileManager1",
         "--talk-name=org.gnome.SettingsDaemon",
         "--talk-name=org.gtk.vfs",
-        "--talk-name=org.gtk.vfs.*"
+        "--talk-name=org.gtk.vfs.*",
+        "--talk-name=org.freedesktop.secrets"
     ],
     "cleanup" : [
         "/include",
diff --git a/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala 
b/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
index 82448e26..49eacf73 100644
--- a/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
+++ b/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
@@ -90,7 +90,7 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
         private WebAuthenticationPane pane;
 
         public Flickr(Spit.Publishing.PluginHost host) {
-            base(API_KEY, API_SECRET, host);
+            base("Flickr", API_KEY, API_SECRET, host);
         }
 
         public override void authenticate() {
diff --git a/plugins/authenticator/shotwell/OAuth1Authenticator.vala 
b/plugins/authenticator/shotwell/OAuth1Authenticator.vala
index 39752ece..4ab19e9d 100644
--- a/plugins/authenticator/shotwell/OAuth1Authenticator.vala
+++ b/plugins/authenticator/shotwell/OAuth1Authenticator.vala
@@ -11,10 +11,18 @@ namespace Publishing.Authenticator.Shotwell.OAuth1 {
         protected GLib.HashTable<string, Variant> params;
         protected Publishing.RESTSupport.OAuth1.Session session;
         protected Spit.Publishing.PluginHost host;
+        private Secret.Schema? schema = null;
+        private const string SECRET_TYPE_USERNAME = "username";
+        private const string SECRET_TYPE_AUTH_TOKEN = "auth-token";
+        private const string SECRET_TYPE_AUTH_TOKEN_SECRET = "auth-token-secret";
+        private string service = null;
 
-        protected Authenticator(string api_key, string api_secret, Spit.Publishing.PluginHost host) {
+        protected Authenticator(string service, string api_key, string api_secret, 
Spit.Publishing.PluginHost host) {
             base();
             this.host = host;
+            this.service = service;
+            this.schema = new Secret.Schema ("org.gnome.Shotwell." + service, Secret.SchemaFlags.NONE,
+                                             "type", Secret.SchemaAttributeType.STRING);
 
             params = new GLib.HashTable<string, Variant>(str_hash, str_equal);
             params.insert("ConsumerKey", api_key);
@@ -43,9 +51,9 @@ namespace Publishing.Authenticator.Shotwell.OAuth1 {
         public abstract void refresh();
 
         public void invalidate_persistent_session() {
-            set_persistent_access_phase_token("");
-            set_persistent_access_phase_token_secret("");
-            set_persistent_access_phase_username("");
+            set_persistent_access_phase_token(null);
+            set_persistent_access_phase_token_secret(null);
+            set_persistent_access_phase_username(null);
         }
         protected bool is_persistent_session_valid() {
             return (get_persistent_access_phase_username() != null &&
@@ -54,27 +62,78 @@ namespace Publishing.Authenticator.Shotwell.OAuth1 {
         }
 
         protected string? get_persistent_access_phase_username() {
-            return host.get_config_string("access_phase_username", null);
+            try {
+                return Secret.password_lookup_sync(this.schema, null, "type", SECRET_TYPE_USERNAME);
+            } catch (Error err) {
+                critical("Failed to lookup username from password store: %s", err.message);
+                return null;
+            }
         }
 
-        protected void set_persistent_access_phase_username(string username) {
-            host.set_config_string("access_phase_username", username);
+        protected void set_persistent_access_phase_username(string? username) {
+            try {
+                if (username == null || username == "") {
+                    Secret.password_clear_sync(this.schema, Secret.COLLECTION_DEFAULT,
+                                               "Shotwell publishing (%s)".printf(this.service),
+                                               "type", SECRET_TYPE_USERNAME);
+                } else {
+                    Secret.password_store_sync(this.schema, Secret.COLLECTION_DEFAULT,
+                                               "Shotwell publishing (%s)".printf(this.service),
+                                               username, null, "type", SECRET_TYPE_USERNAME);
+                }
+            } catch (Error err) {
+                critical("Failed to store username in store: %s", err.message);
+            }
         }
 
         protected string? get_persistent_access_phase_token() {
-            return host.get_config_string("access_phase_token", null);
+            try {
+                return Secret.password_lookup_sync(this.schema, null, "type", SECRET_TYPE_AUTH_TOKEN);
+            } catch (Error err) {
+                critical("Failed to lookup auth-token from password store: %s", err.message);
+                return null;
+            }
         }
 
-        protected void set_persistent_access_phase_token(string token) {
-            host.set_config_string("access_phase_token", token);
+        protected void set_persistent_access_phase_token(string? token) {
+            try {
+                if (token == null || token == "") {
+                    Secret.password_clear_sync(this.schema, Secret.COLLECTION_DEFAULT,
+                                               "Shotwell publishing (%s").printf(this.service),
+                                               "type", SECRET_TYPE_AUTH_TOKEN);
+                } else {
+                    Secret.password_store_sync(this.schema, Secret.COLLECTION_DEFAULT,
+                                               "Shotwell publishing (%s)".printf(this.service),
+                                               token, null, "type", SECRET_TYPE_AUTH_TOKEN);
+                }
+            } catch (Error err) {
+                critical("Failed to store auth-token store: %s", err.message);
+            }
         }
 
         protected string? get_persistent_access_phase_token_secret() {
-            return host.get_config_string("access_phase_token_secret", null);
+            try {
+                return Secret.password_lookup_sync(this.schema, null, "type", SECRET_TYPE_AUTH_TOKEN_SECRET);
+            } catch (Error err) {
+                critical("Failed to lookup auth-token-secret from password store: %s", err.message);
+                return null;
+            }
         }
 
-        protected void set_persistent_access_phase_token_secret(string secret) {
-            host.set_config_string("access_phase_token_secret", secret);
+        protected void set_persistent_access_phase_token_secret(string? secret) {
+            try {
+                if (secrent == null || secret == "") {
+                    Secret.password_clear_sync(this.schema, Secret.COLLECTION_DEFAULT,
+                                               "Shotwell publishing (%s").printf(this.service),
+                                               "type", SECRET_TYPE_AUTH_TOKEN_SECRET);
+                } else {
+                    Secret.password_store_sync(this.schema, Secret.COLLECTION_DEFAULT,
+                                               "Shotwell publishing (%s)".printf(this.service),
+                                               secret, null, "type", SECRET_TYPE_AUTH_TOKEN_SECRET);
+                }
+            } catch (Error err) {
+                critical("Failed to store auth-token-secret store: %s", err.message);
+            }
         }
 
 
diff --git a/plugins/authenticator/shotwell/TumblrAuthenticator.vala 
b/plugins/authenticator/shotwell/TumblrAuthenticator.vala
index 35fdce98..72904d52 100644
--- a/plugins/authenticator/shotwell/TumblrAuthenticator.vala
+++ b/plugins/authenticator/shotwell/TumblrAuthenticator.vala
@@ -127,7 +127,7 @@ namespace Publishing.Authenticator.Shotwell.Tumblr {
 
     internal class Tumblr : Publishing.Authenticator.Shotwell.OAuth1.Authenticator {
         public Tumblr(Spit.Publishing.PluginHost host) {
-            base(API_KEY, API_SECRET, host);
+            base("Tumblr", API_KEY, API_SECRET, host);
         }
 
         public override void authenticate() {


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