[shotwell/wip/pluggable-auth: 17/20] wip: Facebook: Move persitency into authenticator
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/pluggable-auth: 17/20] wip: Facebook: Move persitency into authenticator
- Date: Thu, 9 Feb 2017 22:06:03 +0000 (UTC)
commit 1c9ef11faf3e64223cb69507d2ff546542d47c12
Author: Jens Georg <mail jensge org>
Date: Thu Feb 9 22:16:53 2017 +0100
wip: Facebook: Move persitency into authenticator
Signed-off-by: Jens Georg <mail jensge org>
.../shotwell/FacebookPublishingAuthenticator.vala | 34 +++++++++++++
.../shotwell-publishing/FacebookPublishing.vala | 53 +------------------
2 files changed, 37 insertions(+), 50 deletions(-)
---
diff --git a/plugins/authenticator/shotwell/FacebookPublishingAuthenticator.vala
b/plugins/authenticator/shotwell/FacebookPublishingAuthenticator.vala
index 4aa4fa4..3cab73b 100644
--- a/plugins/authenticator/shotwell/FacebookPublishingAuthenticator.vala
+++ b/plugins/authenticator/shotwell/FacebookPublishingAuthenticator.vala
@@ -174,6 +174,16 @@ namespace Publishing.Authenticator.Shotwell.Facebook {
}
public void authenticate() {
+ // Do we have saved user credentials? If so, go ahead and authenticate the session
+ // with the saved credentials and proceed with the publishing interaction. Otherwise, show
+ // the Welcome pane
+ if (is_persistent_session_valid()) {
+ var access_token = get_persistent_access_token();
+ this.params.insert("AccessToken", new Variant.string(access_token));
+ this.authenticated();
+ return;
+ }
+
// FIXME: Find a way for a proper logout
if (WebAuthenticationPane.is_cache_dirty()) {
host.set_service_locked(false);
@@ -193,12 +203,35 @@ namespace Publishing.Authenticator.Shotwell.Facebook {
}
public void invalidate_persistent_session() {
+ debug("invalidating saved Facebook session.");
+ set_persistent_access_token("");
}
public void logout() {
+ invalidate_persistent_session();
}
/* Private functions */
+ private bool is_persistent_session_valid() {
+ string? token = get_persistent_access_token();
+
+ if (token != null)
+ debug("existing Facebook session found in configuration database (access_token = %s).",
+ token);
+ else
+ debug("no existing Facebook session available.");
+
+ return token != null;
+ }
+
+ private string? get_persistent_access_token() {
+ return host.get_config_string("access_token", null);
+ }
+
+ private void set_persistent_access_token(string access_token) {
+ host.set_config_string("access_token", access_token);
+ }
+
private void do_show_service_welcome_pane() {
debug("ACTION: showing service welcome pane.");
@@ -273,6 +306,7 @@ namespace Publishing.Authenticator.Shotwell.Facebook {
// remove the key from the session description string
access_token = access_token.replace("#access_token=", "");
this.params.insert("AccessToken", new Variant.string(access_token));
+ set_persistent_access_token(access_token);
this.authenticated();
}
diff --git a/plugins/shotwell-publishing/FacebookPublishing.vala
b/plugins/shotwell-publishing/FacebookPublishing.vala
index e61db22..d9477f2 100644
--- a/plugins/shotwell-publishing/FacebookPublishing.vala
+++ b/plugins/shotwell-publishing/FacebookPublishing.vala
@@ -194,30 +194,10 @@ public class FacebookPublisher : Spit.Publishing.Publisher, GLib.Object {
graph_session.authenticated.connect(on_session_authenticated);
}
- private bool is_persistent_session_valid() {
- string? token = get_persistent_access_token();
-
- if (token != null)
- debug("existing Facebook session found in configuration database (access_token = %s).",
- token);
- else
- debug("no existing Facebook session available.");
-
- return token != null;
- }
-
- private string? get_persistent_access_token() {
- return host.get_config_string("access_token", null);
- }
-
private bool get_persistent_strip_metadata() {
return host.get_config_bool("strip_metadata", false);
}
- private void set_persistent_access_token(string access_token) {
- host.set_config_string("access_token", access_token);
- }
-
private void set_persistent_strip_metadata(bool strip_metadata) {
host.set_config_bool("strip_metadata", strip_metadata);
}
@@ -232,12 +212,6 @@ public class FacebookPublisher : Spit.Publishing.Publisher, GLib.Object {
host.set_config_int("default_size", size);
}
- private void invalidate_persistent_session() {
- debug("invalidating saved Facebook session.");
-
- set_persistent_access_token("");
- }
-
/*
private void do_test_connection_to_endpoint() {
debug("ACTION: testing connection to Facebook endpoint.");
@@ -380,8 +354,6 @@ public class FacebookPublisher : Spit.Publishing.Publisher, GLib.Object {
debug("ACTION: clearing persistent session information and restaring interaction.");
this.authenticator.logout();
- invalidate_persistent_session();
-
running = false;
start();
}
@@ -426,12 +398,6 @@ public class FacebookPublisher : Spit.Publishing.Publisher, GLib.Object {
graph_session.authenticate(access_token.get_string());
}
- private void do_save_session_information() {
- debug("ACTION: saving session information to configuration system.");
-
- set_persistent_access_token(graph_session.get_access_token());
- }
-
private void do_upload() {
debug("ACTION: uploading photos to album '%s'",
publishing_params.target_album == PublishingParameters.UNKNOWN_ALBUM ? "(none)" :
@@ -509,7 +475,6 @@ public class FacebookPublisher : Spit.Publishing.Publisher, GLib.Object {
assert(graph_session.is_authenticated());
debug("EVENT: an authenticated session has become available.");
- do_save_session_information();
do_fetch_user_info();
}
@@ -714,16 +679,9 @@ public class FacebookPublisher : Spit.Publishing.Publisher, GLib.Object {
// actually a restart
publishing_params = new PublishingParameters();
- // Do we have saved user credentials? If so, go ahead and authenticate the session
- // with the saved credentials and proceed with the publishing interaction. Otherwise, show
- // the Welcome pane
- if (is_persistent_session_valid()) {
- graph_session.authenticate(get_persistent_access_token());
- } else {
- this.authenticator.authenticated.connect(on_authenticator_succeeded);
- this.authenticator.authentication_failed.connect(on_authenticator_failed);
- this.authenticator.authenticate();
- }
+ this.authenticator.authenticated.connect(on_authenticator_succeeded);
+ this.authenticator.authentication_failed.connect(on_authenticator_failed);
+ this.authenticator.authenticate();
}
public void stop() {
@@ -1306,11 +1264,6 @@ internal class GraphSession {
return access_token != null;
}
- public string get_access_token() {
- assert(is_authenticated());
- return access_token;
- }
-
#if 0
public GraphMessage new_endpoint_test() {
return new GraphEndpointProbeMessage(this);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]