From 18b52c2983a1b3409011f72d27f15de576c5eb1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Fri, 20 Jul 2018 23:08:09 +0200 Subject: New upstream version 0.28.4 --- .../shotwell/GoogleAuthenticator.vala | 53 +++++++++++++++------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to 'plugins/authenticator/shotwell/GoogleAuthenticator.vala') diff --git a/plugins/authenticator/shotwell/GoogleAuthenticator.vala b/plugins/authenticator/shotwell/GoogleAuthenticator.vala index 9271b57..f561197 100644 --- a/plugins/authenticator/shotwell/GoogleAuthenticator.vala +++ b/plugins/authenticator/shotwell/GoogleAuthenticator.vala @@ -3,34 +3,53 @@ using Shotwell.Plugins; namespace Publishing.Authenticator.Shotwell.Google { private const string OAUTH_CLIENT_ID = "534227538559-hvj2e8bj0vfv2f49r7gvjoq6jibfav67.apps.googleusercontent.com"; + private const string REVERSE_CLIENT_ID = "com.googleusercontent.apps.534227538559-hvj2e8bj0vfv2f49r7gvjoq6jibfav67"; private const string OAUTH_CLIENT_SECRET = "pwpzZ7W1TCcD5uIfYCu8sM7x"; + private const string OAUTH_CALLBACK_URI = REVERSE_CLIENT_ID + ":/auth-callback"; private class WebAuthenticationPane : Common.WebAuthenticationPane { public static bool cache_dirty = false; + private string? auth_code = null; - public signal void authorized(string auth_code); + public signal void error(); - public WebAuthenticationPane(string auth_sequence_start_url) { - Object (login_uri : auth_sequence_start_url); - } + public override void constructed() { + base.constructed(); - public static bool is_cache_dirty() { - return cache_dirty; + var ctx = WebKit.WebContext.get_default(); + ctx.register_uri_scheme(REVERSE_CLIENT_ID, this.on_shotwell_auth_request_cb); } public override void on_page_load() { - string page_title = get_view ().get_title(); - if (page_title.index_of("state=connect") > 0) { - int auth_code_field_start = page_title.index_of("code="); - if (auth_code_field_start < 0) - return; + var uri = new Soup.URI(get_view().get_uri()); + if (uri.scheme == REVERSE_CLIENT_ID && this.auth_code == null) { + this.error(); + } - string auth_code = page_title.substring(auth_code_field_start + 5); // 5 = "code=".length + if (this.auth_code != null) { + this.authorized(this.auth_code); + } + } - cache_dirty = true; + private void on_shotwell_auth_request_cb(WebKit.URISchemeRequest request) { + var uri = new Soup.URI(request.get_uri()); + debug("URI: %s", request.get_uri()); + var form_data = Soup.Form.decode (uri.query); + this.auth_code = form_data.lookup("code"); - authorized(auth_code); - } + var response = ""; + var mins = new MemoryInputStream.from_data(response.data, null); + request.finish(mins, -1, "text/plain"); + } + + public signal void authorized(string auth_code); + + public WebAuthenticationPane(string auth_sequence_start_url) { + Object (login_uri : auth_sequence_start_url); + } + + public static bool is_cache_dirty() { + return cache_dirty; } } @@ -59,7 +78,7 @@ namespace Publishing.Authenticator.Shotwell.Google { add_argument("code", auth_code); add_argument("client_id", OAUTH_CLIENT_ID); add_argument("client_secret", OAUTH_CLIENT_SECRET); - add_argument("redirect_uri", "urn:ietf:wg:oauth:2.0:oob"); + add_argument("redirect_uri", OAUTH_CALLBACK_URI); add_argument("grant_type", "authorization_code"); } } @@ -144,7 +163,7 @@ namespace Publishing.Authenticator.Shotwell.Google { string user_authorization_url = "https://accounts.google.com/o/oauth2/auth?" + "response_type=code&" + "client_id=" + OAUTH_CLIENT_ID + "&" + - "redirect_uri=" + Soup.URI.encode("urn:ietf:wg:oauth:2.0:oob", null) + "&" + + "redirect_uri=" + Soup.URI.encode(OAUTH_CALLBACK_URI, null) + "&" + "scope=" + Soup.URI.encode(this.scope, null) + "+" + Soup.URI.encode("https://www.googleapis.com/auth/userinfo.profile", null) + "&" + "state=connect&" + -- cgit v1.2.3