summaryrefslogtreecommitdiff
path: root/plugins/authenticator/shotwell/GoogleAuthenticator.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2018-08-05 08:00:12 +0200
committerJörg Frings-Fürst <debian@jff.email>2018-08-05 08:00:12 +0200
commit8ae550d463720d5d1c0e253af29843ff15de1a54 (patch)
treeb6be28a7d546e7a174910ee83d6af555ed8860fa /plugins/authenticator/shotwell/GoogleAuthenticator.vala
parent709e2d6f5652ec90c194a4ec2b530bebc6f952cb (diff)
parent9df0619e4e581eac73e5f3b76d271f1fff192f81 (diff)
Merge branch 'release/debian/0.28.4-1'debian/0.28.4-1
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&" +