summaryrefslogtreecommitdiff
path: root/plugins/authenticator/shotwell/GoogleAuthenticator.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2018-07-20 23:09:20 +0200
committerJörg Frings-Fürst <debian@jff.email>2018-07-20 23:09:20 +0200
commit850e65ba4fe8b08f88912e637e2e469cf367b3f6 (patch)
tree3b5255dd7045526bd6cd95c9dd3316bf4fe8977b /plugins/authenticator/shotwell/GoogleAuthenticator.vala
parent313caf3932fab12b6cbf9c4f11cd80c8f25c92cf (diff)
parent18b52c2983a1b3409011f72d27f15de576c5eb1c (diff)
Update upstream source from tag 'upstream/0.28.4'
Update to upstream version '0.28.4' with Debian dir 6b82ec3fb97aab0b3e4bb752f68e0be9dfaea63e
Diffstat (limited to 'plugins/authenticator/shotwell/GoogleAuthenticator.vala')
-rw-r--r--plugins/authenticator/shotwell/GoogleAuthenticator.vala53
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&" +