diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2018-07-20 23:24:50 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2018-07-20 23:24:50 +0200 |
commit | 871b797a84db1fd625fe13991d4da2bb25adc1d2 (patch) | |
tree | 95dd14c2998d80bbea4c33d207a0a1fca8184635 /plugins/authenticator/shotwell/GoogleAuthenticator.vala | |
parent | 313caf3932fab12b6cbf9c4f11cd80c8f25c92cf (diff) | |
parent | a099c47b6645d9642e49144d83b26e609fa5ec2f (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'plugins/authenticator/shotwell/GoogleAuthenticator.vala')
-rw-r--r-- | plugins/authenticator/shotwell/GoogleAuthenticator.vala | 53 |
1 files changed, 36 insertions, 17 deletions
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&" + |