summaryrefslogtreecommitdiff
path: root/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala')
-rw-r--r--plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala106
1 files changed, 41 insertions, 65 deletions
diff --git a/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala b/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
index 82448e2..26af6d1 100644
--- a/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
+++ b/plugins/authenticator/shotwell/FlickrPublishingAuthenticator.vala
@@ -21,7 +21,7 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
public AuthenticationRequestTransaction(Publishing.RESTSupport.OAuth1.Session session) {
base.with_uri(session, "https://www.flickr.com/services/oauth/request_token",
Publishing.RESTSupport.HttpMethod.GET);
- add_argument("oauth_callback", "shotwell-auth%3A%2F%2Flocal-callback");
+ add_argument("oauth_callback", "shotwell-auth://local-callback");
}
}
@@ -31,7 +31,7 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
Publishing.RESTSupport.HttpMethod.GET);
add_argument("oauth_verifier", user_verifier);
add_argument("oauth_token", session.get_request_phase_token());
- add_argument("oauth_callback", "shotwell-auth%3A%2F%2Flocal-callback");
+ add_argument("oauth_callback", "shotwell-auth://local-callback");
}
}
@@ -64,10 +64,16 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
return;
}
- var uri = new Soup.URI(get_view().get_uri());
- if (uri.scheme == "shotwell-auth" && this.auth_code == null) {
- var form_data = Soup.Form.decode (uri.query);
- this.auth_code = form_data.lookup("oauth_verifier");
+ try {
+ var uri = GLib.Uri.parse(get_view().get_uri(), GLib.UriFlags.NONE);
+ if (uri.get_scheme() == "shotwell-auth" && this.auth_code == null) {
+ var form_data = Soup.Form.decode (uri.get_query());
+ this.auth_code = form_data.lookup("oauth_verifier");
+ }
+ } catch (Error err) {
+ this.error();
+
+ return;
}
if (this.auth_code != null) {
@@ -76,9 +82,13 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
}
private void on_shotwell_auth_request_cb(WebKit.URISchemeRequest request) {
- var uri = new Soup.URI(request.get_uri());
- var form_data = Soup.Form.decode (uri.query);
- this.auth_code = form_data.lookup("oauth_verifier");
+ try {
+ var uri = GLib.Uri.parse(request.get_uri(), GLib.UriFlags.NONE);
+ var form_data = Soup.Form.decode (uri.get_query());
+ this.auth_code = form_data.lookup("oauth_verifier");
+ } catch (Error err) {
+ debug ("Failed to parse URI %s: %s", request.get_uri(), err.message);
+ }
var response = "";
var mins = new MemoryInputStream.from_data(response.data, null);
@@ -90,7 +100,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() {
@@ -128,45 +138,27 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
private void on_welcome_pane_login_clicked() {
debug("EVENT: user clicked 'Login' button in the welcome pane");
- do_run_authentication_request_transaction();
+ do_run_authentication_request_transaction.begin();
}
- private void do_run_authentication_request_transaction() {
+ private async void do_run_authentication_request_transaction() {
debug("ACTION: running authentication request transaction");
host.set_service_locked(true);
host.install_static_message_pane(_("Preparing for login…"));
AuthenticationRequestTransaction txn = new AuthenticationRequestTransaction(session);
- txn.completed.connect(on_auth_request_txn_completed);
- txn.network_error.connect(on_auth_request_txn_error);
-
try {
- txn.execute();
- } catch (Spit.Publishing.PublishingError err) {
+ yield txn.execute_async();
+ debug("EVENT: OAuth authentication request transaction completed; response = '%s'",
+ txn.get_response());
+ do_parse_token_info_from_auth_request(txn.get_response());
+ } catch (Error err) {
+ debug("EVENT: OAuth authentication request transaction caused a network error");
host.post_error(err);
- }
- }
-
- private void on_auth_request_txn_completed(Publishing.RESTSupport.Transaction txn) {
- txn.completed.disconnect(on_auth_request_txn_completed);
- txn.network_error.disconnect(on_auth_request_txn_error);
-
- debug("EVENT: OAuth authentication request transaction completed; response = '%s'",
- txn.get_response());
-
- do_parse_token_info_from_auth_request(txn.get_response());
- }
- private void on_auth_request_txn_error(Publishing.RESTSupport.Transaction txn,
- Spit.Publishing.PublishingError err) {
- txn.completed.disconnect(on_auth_request_txn_completed);
- txn.network_error.disconnect(on_auth_request_txn_error);
-
- debug("EVENT: OAuth authentication request transaction caused a network error");
- host.post_error(err);
-
- this.authentication_failed();
+ this.authentication_failed();
+ }
}
private void do_parse_token_info_from_auth_request(string response) {
@@ -199,7 +191,7 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
private void do_web_authentication(string token) {
pane = new WebAuthenticationPane(token);
host.install_dialog_pane(pane);
- pane.authorized.connect(this.do_verify_pin);
+ pane.authorized.connect((pin) => { this.do_verify_pin.begin(pin); });
pane.error.connect(this.on_web_login_error);
}
@@ -211,44 +203,28 @@ namespace Publishing.Authenticator.Shotwell.Flickr {
host.post_error(new Spit.Publishing.PublishingError.PROTOCOL_ERROR(_("Flickr authorization failed")));
}
- private void do_verify_pin(string pin) {
+ private async void do_verify_pin(string pin) {
debug("ACTION: validating authorization PIN %s", pin);
host.set_service_locked(true);
host.install_static_message_pane(_("Verifying authorization…"));
AccessTokenFetchTransaction txn = new AccessTokenFetchTransaction(session, pin);
- txn.completed.connect(on_access_token_fetch_txn_completed);
- txn.network_error.connect(on_access_token_fetch_error);
try {
- txn.execute();
- } catch (Spit.Publishing.PublishingError err) {
- host.post_error(err);
- }
- }
-
- private void on_access_token_fetch_txn_completed(Publishing.RESTSupport.Transaction txn) {
- txn.completed.disconnect(on_access_token_fetch_txn_completed);
- txn.network_error.disconnect(on_access_token_fetch_error);
+ yield txn.execute_async();
+ debug("EVENT: fetching OAuth access token over the network succeeded");
- debug("EVENT: fetching OAuth access token over the network succeeded");
+ do_extract_access_phase_credentials_from_response(txn.get_response());
+ } catch (Error err) {
+ debug("EVENT: fetching OAuth access token over the network caused an error.");
- do_extract_access_phase_credentials_from_reponse(txn.get_response());
- }
-
- private void on_access_token_fetch_error(Publishing.RESTSupport.Transaction txn,
- Spit.Publishing.PublishingError err) {
- txn.completed.disconnect(on_access_token_fetch_txn_completed);
- txn.network_error.disconnect(on_access_token_fetch_error);
-
- debug("EVENT: fetching OAuth access token over the network caused an error.");
-
- host.post_error(err);
- this.authentication_failed();
+ host.post_error(err);
+ this.authentication_failed();
+ }
}
- private void do_extract_access_phase_credentials_from_reponse(string response) {
+ private void do_extract_access_phase_credentials_from_response(string response) {
debug("ACTION: extracting access phase credentials from '%s'", response);
string? token = null;