[shotwell/wip/pluggable-auth: 11/16] wip: flickr: Move persistency to authenticator



commit 3be5012b56c0bc6c98bc0b84e8fa7843e261e28b
Author: Jens Georg <mail jensge org>
Date:   Thu Feb 9 21:36:14 2017 +0100

    wip: flickr: Move persistency to authenticator
    
    Signed-off-by: Jens Georg <mail jensge org>

 .../shotwell/FlickrPublishingAuthenticator.vala    |   87 +++++++++++++++++---
 plugins/shotwell-publishing/FlickrPublishing.vala  |   87 +------------------
 2 files changed, 81 insertions(+), 93 deletions(-)
---
diff --git a/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala 
b/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
index 006987c..7b92cac 100644
--- a/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
+++ b/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
@@ -13,18 +13,17 @@ namespace Publishing.Flickr {
         public Transaction(Session session, Publishing.RESTSupport.HttpMethod method =
                 Publishing.RESTSupport.HttpMethod.POST) {
             base(session, method);
-
-            add_argument("oauth_nonce", session.get_oauth_nonce());
-            add_argument("oauth_signature_method", "HMAC-SHA1");
-            add_argument("oauth_version", "1.0");
-            add_argument("oauth_callback", "oob");
-            add_argument("oauth_timestamp", session.get_oauth_timestamp());
-            add_argument("oauth_consumer_key", session.get_consumer_key());
+            setup_arguments();
         }
 
         public Transaction.with_uri(Session session, string uri,
                 Publishing.RESTSupport.HttpMethod method = Publishing.RESTSupport.HttpMethod.POST) {
             base.with_endpoint_url(session, uri, method);
+            setup_arguments();
+        }
+
+        private void setup_arguments() {
+            var session = (Session) get_parent_session();
 
             add_argument("oauth_nonce", session.get_oauth_nonce());
             add_argument("oauth_signature_method", "HMAC-SHA1");
@@ -34,6 +33,7 @@ namespace Publishing.Flickr {
             add_argument("oauth_consumer_key", session.get_consumer_key());
         }
 
+
         public override void execute() throws Spit.Publishing.PublishingError {
             ((Session) get_parent_session()).sign_transaction(this);
 
@@ -59,6 +59,21 @@ namespace Publishing.Flickr {
                     username != null);
         }
 
+        public void authenticate_from_persistent_credentials(string token, string secret,
+                string username) {
+            this.access_phase_token = token;
+            this.access_phase_token_secret = secret;
+            this.username = username;
+
+            authenticated();
+        }
+
+        public void deauthenticate() {
+            access_phase_token = null;
+            access_phase_token_secret = null;
+            username = null;
+        }
+
         public void set_api_credentials(string consumer_key, string consumer_secret) {
             this.consumer_key = consumer_key;
             this.consumer_secret = consumer_secret;
@@ -272,8 +287,53 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
             session.authenticated.disconnect(on_session_authenticated);
         }
 
+        public void invalidate_persistent_session() {
+            set_persistent_access_phase_token("");
+            set_persistent_access_phase_token_secret("");
+            set_persistent_access_phase_username("");
+        }
+
+        private bool is_persistent_session_valid() {
+            return (get_persistent_access_phase_username() != null &&
+                    get_persistent_access_phase_token() != null &&
+                    get_persistent_access_phase_token_secret() != null);
+        }
+
+        private string? get_persistent_access_phase_username() {
+            return host.get_config_string("access_phase_username", null);
+        }
+
+        private void set_persistent_access_phase_username(string username) {
+            host.set_config_string("access_phase_username", username);
+        }
+
+        private string? get_persistent_access_phase_token() {
+            return host.get_config_string("access_phase_token", null);
+        }
+
+        private void set_persistent_access_phase_token(string token) {
+            host.set_config_string("access_phase_token", token);
+        }
+
+        private string? get_persistent_access_phase_token_secret() {
+            return host.get_config_string("access_phase_token_secret", null);
+        }
+
+        private void set_persistent_access_phase_token_secret(string secret) {
+            host.set_config_string("access_phase_token_secret", secret);
+        }
+
         public void authenticate() {
-            do_show_login_welcome_pane();
+            if (is_persistent_session_valid()) {
+                debug("attempt start: a persistent session is available; using it");
+
+                session.authenticate_from_persistent_credentials(get_persistent_access_phase_token(),
+                        get_persistent_access_phase_token_secret(), get_persistent_access_phase_username());
+            } else {
+                debug("attempt start: no persistent session available; showing login welcome pane");
+                do_show_login_welcome_pane();
+            }
+
         }
 
         public bool can_logout() {
@@ -284,10 +344,9 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
             return this.params;
         }
 
-        public void invalidate_persistent_session() {
-        }
-
         public void logout () {
+            session.deauthenticate();
+            invalidate_persistent_session();
         }
 
         private void do_show_login_welcome_pane() {
@@ -488,6 +547,12 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
             params.insert("AuthToken", session.get_access_phase_token());
             params.insert("AuthTokenSecret", session.get_access_phase_token_secret());
             params.insert("Username", session.get_username());
+
+            set_persistent_access_phase_token(session.get_access_phase_token());
+            set_persistent_access_phase_token_secret(session.get_access_phase_token_secret());
+            set_persistent_access_phase_username(session.get_username());
+
+
             this.authenticated();
         }
     }
diff --git a/plugins/shotwell-publishing/FlickrPublishing.vala 
b/plugins/shotwell-publishing/FlickrPublishing.vala
index 6ba3cb8..a768b6e 100644
--- a/plugins/shotwell-publishing/FlickrPublishing.vala
+++ b/plugins/shotwell-publishing/FlickrPublishing.vala
@@ -117,50 +117,14 @@ public class FlickrPublisher : Spit.Publishing.Publisher, GLib.Object {
     ~FlickrPublisher() {
         this.authenticator.authenticated.disconnect(on_session_authenticated);
     }
-    
-    private void invalidate_persistent_session() {
-        set_persistent_access_phase_token("");
-        set_persistent_access_phase_token_secret("");
-        set_persistent_access_phase_username("");
-    }
-    
-    private bool is_persistent_session_valid() {
-        return (get_persistent_access_phase_username() != null &&
-                get_persistent_access_phase_token() != null &&
-                get_persistent_access_phase_token_secret() != null);
-    }
-    
-    private string? get_persistent_access_phase_username() {
-        return host.get_config_string("access_phase_username", null);
-    }
-    
-    private void set_persistent_access_phase_username(string username) {
-        host.set_config_string("access_phase_username", username);
-    }
-
-    private string? get_persistent_access_phase_token() {
-        return host.get_config_string("access_phase_token", null);
-    }
-
-    private void set_persistent_access_phase_token(string token) {
-        host.set_config_string("access_phase_token", token);
-    }
-
-    private string? get_persistent_access_phase_token_secret() {
-        return host.get_config_string("access_phase_token_secret", null);
-    }
-
-    private void set_persistent_access_phase_token_secret(string secret) {
-        host.set_config_string("access_phase_token_secret", secret);
-    }
 
     private bool get_persistent_strip_metadata() {
         return host.get_config_bool("strip_metadata", false);
     }
-    
+
     private void set_persistent_strip_metadata(bool strip_metadata) {
         host.set_config_bool("strip_metadata", strip_metadata);
-    }    
+    }
 
     private void on_session_authenticated() {
         if (!is_running())
@@ -187,10 +151,6 @@ public class FlickrPublisher : Spit.Publishing.Publisher, GLib.Object {
 
         parameters.username = session.get_username();
 
-        set_persistent_access_phase_token(session.get_access_phase_token());
-        set_persistent_access_phase_token_secret(session.get_access_phase_token_secret());
-        set_persistent_access_phase_username(session.get_username());
-
         do_fetch_account_info();
     }
 
@@ -349,8 +309,9 @@ public class FlickrPublisher : Spit.Publishing.Publisher, GLib.Object {
     private void do_logout() {
         debug("ACTION: logging user out, deauthenticating session, and erasing stored credentials");
 
-        session.deauthenticate();
-        invalidate_persistent_session();
+        if (authenticator.can_logout()) {
+            authenticator.logout();
+        }
 
         running = false;
 
@@ -455,24 +416,6 @@ public class FlickrPublisher : Spit.Publishing.Publisher, GLib.Object {
         running = true;
         was_started = true;
         
-        if (is_persistent_session_valid()) {
-            debug("attempt start: a persistent session is available; using it");
-            var params = this.authenticator.get_authentication_parameter();
-            Variant consumer_key = null;
-            Variant consumer_secret = null;
-
-            params.lookup_extended("ConsumerKey", null, out consumer_key);
-            params.lookup_extended("ConsumerSecret", null, out consumer_secret);
-            session.set_api_credentials(consumer_key.get_string(),
-                    consumer_secret.get_string());
-
-            session.authenticate_from_persistent_credentials(get_persistent_access_phase_token(),
-                get_persistent_access_phase_token_secret(), get_persistent_access_phase_username());
-            do_fetch_account_info();
-        } else {
-            debug("attempt start: no persistent session available; showing login welcome pane");
-            authenticator.authenticate();
-        }
     }
     
     public void start() {
@@ -678,21 +621,6 @@ internal class Session : Publishing.RESTSupport.Session {
             username != null);
     }
 
-    public void authenticate_from_persistent_credentials(string token, string secret,
-        string username) {
-        this.access_phase_token = token;
-        this.access_phase_token_secret = secret;
-        this.username = username;
-        
-        authenticated();
-    }
-    
-    public void deauthenticate() {
-        access_phase_token = null;
-        access_phase_token_secret = null;
-        username = null;
-    }
-
     public void set_api_credentials(string consumer_key, string consumer_secret) {
         this.consumer_key = consumer_key;
         this.consumer_secret = consumer_secret;
@@ -790,11 +718,6 @@ internal class Session : Publishing.RESTSupport.Session {
         return access_phase_token;
     }
     
-    public string get_access_phase_token_secret() {
-        assert(access_phase_token_secret != null);
-        return access_phase_token_secret;
-    }
-    
     public string get_username() {
         assert(is_authenticated());
         return username;


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