Merge lp:~mardy/account-plugins/usernames-1565772 into lp:account-plugins

Proposed by Alberto Mardegan
Status: Merged
Approved by: David Barth
Approved revision: 160
Merged at revision: 156
Proposed branch: lp:~mardy/account-plugins/usernames-1565772
Merge into: lp:account-plugins
Diff against target: 540 lines (+279/-29)
21 files modified
.bzrignore (+5/-0)
Makefile.am (+26/-6)
configure.ac (+4/-1)
data/providers/facebook.provider.in.in (+1/-1)
data/providers/flickr.provider.in.in (+1/-1)
data/providers/twitter.provider.in.in (+1/-1)
data/webkit-options/api.twitter.com.conf (+0/-2)
data/webkit-options/login.yahoo.com.conf (+0/-2)
data/webkit-options/www.facebook.com.conf (+0/-7)
debian/account-plugin-facebook.install (+0/-1)
debian/account-plugin-flickr.install (+0/-1)
debian/account-plugin-twitter.install (+0/-1)
debian/changelog (+15/-0)
debian/control (+27/-4)
debian/libaccount-plugin-facebook.install (+1/-0)
debian/libaccount-plugin-flickr.install (+1/-0)
debian/libaccount-plugin-twitter.install (+1/-0)
src/facebook.vala (+69/-0)
src/flickr.vala (+41/-0)
src/google.vala (+40/-1)
src/twitter.vala (+46/-0)
To merge this branch: bzr merge lp:~mardy/account-plugins/usernames-1565772
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Online Accounts Pending
Review via email: mp+290970@code.launchpad.net

Commit message

Retrieve usernames in Facebook, Flickr, Google and Twitter plugins

Use the new APIs in libaccount-plugin to override the query_username() method; remove the unneeded webkit-options files from some account providers.

Description of the change

Retrieve usernames in Facebook, Flickr, Google and Twitter plugins

Use the new APIs in libaccount-plugin to override the query_username() method; remove the unneeded webkit-options files from some account providers.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2013-03-19 08:52:34 +0000
+++ .bzrignore 2016-04-05 11:21:38 +0000
@@ -6,6 +6,7 @@
6*.service6*.service
7*.substvars7*.substvars
8*.stamp8*.stamp
9*.trs
9INSTALL10INSTALL
10Makefile11Makefile
11Makefile.in12Makefile.in
@@ -50,7 +51,11 @@
50.deps51.deps
51.dirstamp52.dirstamp
52.libs53.libs
54/src/facebook.c
55/src/flickr.c
53/src/generic-oauth.c56/src/generic-oauth.c
54/src/google.c57/src/google.c
58/src/twitter.c
59/test-driver
55/test-provider60/test-provider
56/test-service61/test-service
5762
=== modified file 'Makefile.am'
--- Makefile.am 2015-04-17 08:53:11 +0000
+++ Makefile.am 2016-04-05 11:21:38 +0000
@@ -8,8 +8,11 @@
8if ENABLE_LIBACCOUNT_PLUGIN8if ENABLE_LIBACCOUNT_PLUGIN
9# Binary account plugins.9# Binary account plugins.
10plugin_LTLIBRARIES = \10plugin_LTLIBRARIES = \
11 libfacebook.la \
12 libflickr.la \
11 libgeneric-oauth.la \13 libgeneric-oauth.la \
12 libgoogle.la14 libgoogle.la \
15 libtwitter.la
1316
14VALAFLAGS = \17VALAFLAGS = \
15 --vapidir $(top_srcdir)/src \18 --vapidir $(top_srcdir)/src \
@@ -36,12 +39,32 @@
36 -no-undefined \39 -no-undefined \
37 -export-symbols-regex '^ap_module_get_object_type'40 -export-symbols-regex '^ap_module_get_object_type'
3841
39libgoogle_la_CPPFLAGS = $(plugin_cppflags)42libfacebook_la_CPPFLAGS = $(plugin_cppflags) $(RESTAPIS_CFLAGS)
40libgoogle_la_LIBADD = $(plugin_libadd)43libfacebook_la_LIBADD = $(plugin_libadd) $(RESTAPIS_LIBS)
44libfacebook_la_LDFLAGS = $(plugin_ldflags)
45libfacebook_la_VALAFLAGS = --pkg libsoup-2.4 --pkg json-glib-1.0
46libfacebook_la_SOURCES = \
47 src/facebook.vala
48
49libflickr_la_CPPFLAGS = $(plugin_cppflags)
50libflickr_la_LIBADD = $(plugin_libadd)
51libflickr_la_LDFLAGS = $(plugin_ldflags)
52libflickr_la_SOURCES = \
53 src/flickr.vala
54
55libgoogle_la_CPPFLAGS = $(plugin_cppflags) $(RESTAPIS_CFLAGS)
56libgoogle_la_LIBADD = $(plugin_libadd) $(RESTAPIS_LIBS)
41libgoogle_la_LDFLAGS = $(plugin_ldflags)57libgoogle_la_LDFLAGS = $(plugin_ldflags)
58libgoogle_la_VALAFLAGS = --pkg libsoup-2.4 --pkg json-glib-1.0
42libgoogle_la_SOURCES = \59libgoogle_la_SOURCES = \
43 src/google.vala60 src/google.vala
4461
62libtwitter_la_CPPFLAGS = $(plugin_cppflags)
63libtwitter_la_LIBADD = $(plugin_libadd)
64libtwitter_la_LDFLAGS = $(plugin_ldflags)
65libtwitter_la_SOURCES = \
66 src/twitter.vala
67
45libgeneric_oauth_la_CPPFLAGS = $(plugin_cppflags)68libgeneric_oauth_la_CPPFLAGS = $(plugin_cppflags)
46libgeneric_oauth_la_LIBADD = $(plugin_libadd)69libgeneric_oauth_la_LIBADD = $(plugin_libadd)
47libgeneric_oauth_la_LDFLAGS = $(plugin_ldflags)70libgeneric_oauth_la_LDFLAGS = $(plugin_ldflags)
@@ -104,12 +127,9 @@
104 data/webkit-options/api.instagram.com.conf \127 data/webkit-options/api.instagram.com.conf \
105 data/webkit-options/api.weibo.com.conf \128 data/webkit-options/api.weibo.com.conf \
106 data/webkit-options/api.t.sohu.com.conf \129 data/webkit-options/api.t.sohu.com.conf \
107 data/webkit-options/api.twitter.com.conf \
108 data/webkit-options/foursquare.com.conf \130 data/webkit-options/foursquare.com.conf \
109 data/webkit-options/identi.ca.conf \131 data/webkit-options/identi.ca.conf \
110 data/webkit-options/login.live.com.conf \132 data/webkit-options/login.live.com.conf \
111 data/webkit-options/login.yahoo.com.conf \
112 data/webkit-options/www.facebook.com.conf \
113 data/webkit-options/www.linkedin.com.conf133 data/webkit-options/www.linkedin.com.conf
114134
115dist_bin_SCRIPTS = \135dist_bin_SCRIPTS = \
116136
=== modified file 'configure.ac'
--- configure.ac 2014-09-11 10:07:28 +0000
+++ configure.ac 2016-04-05 11:21:38 +0000
@@ -41,7 +41,10 @@
41 [have_libaccount_plugin=no])41 [have_libaccount_plugin=no])
4242
43AS_IF([test "x$have_libaccount_plugin" = "xyes"],43AS_IF([test "x$have_libaccount_plugin" = "xyes"],
44 [PKG_CHECK_MODULES([ACCOUNT_PLUGINS], [account-plugin >= 0.1.3])],44 [
45 PKG_CHECK_MODULES([ACCOUNT_PLUGINS], [account-plugin >= 0.1.3])
46 PKG_CHECK_MODULES([RESTAPIS], [libsoup-2.4 json-glib-1.0])
47 ],
45 [AS_IF([test "x$enable_libaccount_plugin" = "xyes"],48 [AS_IF([test "x$enable_libaccount_plugin" = "xyes"],
46 [AC_MSG_ERROR([libaccount-plugin support enabled but required dependencies were not found])])])49 [AC_MSG_ERROR([libaccount-plugin support enabled but required dependencies were not found])])])
4750
4851
=== modified file 'data/providers/facebook.provider.in.in'
--- data/providers/facebook.provider.in.in 2015-09-09 08:48:32 +0000
+++ data/providers/facebook.provider.in.in 2016-04-05 11:21:38 +0000
@@ -4,7 +4,7 @@
4 <icon>facebook</icon>4 <icon>facebook</icon>
5 <translations>account-plugins</translations>5 <translations>account-plugins</translations>
6 <domains>.*facebook\.com</domains>6 <domains>.*facebook\.com</domains>
7 <plugin>generic-oauth</plugin>7 <plugin>facebook</plugin>
8 <single-account>true</single-account>8 <single-account>true</single-account>
99
10 <template>10 <template>
1111
=== modified file 'data/providers/flickr.provider.in.in'
--- data/providers/flickr.provider.in.in 2013-02-25 06:25:34 +0000
+++ data/providers/flickr.provider.in.in 2016-04-05 11:21:38 +0000
@@ -4,7 +4,7 @@
4 <icon>flickr</icon>4 <icon>flickr</icon>
5 <translations>account-plugins</translations>5 <translations>account-plugins</translations>
6 <domains>.*flickr\.com</domains>6 <domains>.*flickr\.com</domains>
7 <plugin>generic-oauth</plugin>7 <plugin>flickr</plugin>
88
9 <template>9 <template>
10 <group name="auth">10 <group name="auth">
1111
=== modified file 'data/providers/twitter.provider.in.in'
--- data/providers/twitter.provider.in.in 2013-02-22 15:17:49 +0000
+++ data/providers/twitter.provider.in.in 2016-04-05 11:21:38 +0000
@@ -3,7 +3,7 @@
3 <name>Twitter</name>3 <name>Twitter</name>
4 <icon>twitter</icon>4 <icon>twitter</icon>
5 <translations>account-plugins</translations>5 <translations>account-plugins</translations>
6 <plugin>generic-oauth</plugin>6 <plugin>twitter</plugin>
7 <domains>.*twitter\.com</domains>7 <domains>.*twitter\.com</domains>
88
9 <template>9 <template>
1010
=== removed file 'data/webkit-options/api.twitter.com.conf'
--- data/webkit-options/api.twitter.com.conf 2012-06-19 06:08:30 +0000
+++ data/webkit-options/api.twitter.com.conf 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1UsernameField = input[id="username_or_email"]
2PasswordField = input[id="password"]
30
=== removed file 'data/webkit-options/login.yahoo.com.conf'
--- data/webkit-options/login.yahoo.com.conf 2012-06-18 14:24:03 +0000
+++ data/webkit-options/login.yahoo.com.conf 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1UsernameField = input[name="login"]
2PasswordField = input[name="passwd"]
30
=== removed file 'data/webkit-options/www.facebook.com.conf'
--- data/webkit-options/www.facebook.com.conf 2012-05-02 22:58:29 +0000
+++ data/webkit-options/www.facebook.com.conf 1970-01-01 00:00:00 +0000
@@ -1,7 +0,0 @@
1ViewportWidth = 420
2ViewportHeight = 320
3UsernameField = input[name="email"]
4PasswordField = input[name="pass"]
5#ZoomFactor = 2
6#PreferredWidth = 420
7
80
=== modified file 'debian/account-plugin-facebook.install'
--- debian/account-plugin-facebook.install 2015-04-17 08:53:11 +0000
+++ debian/account-plugin-facebook.install 2016-04-05 11:21:38 +0000
@@ -1,4 +1,3 @@
1etc/signon-ui/webkit-options.d/www.facebook.com.conf
2usr/share/accounts/services/facebook-sharing.service1usr/share/accounts/services/facebook-sharing.service
3usr/share/accounts/services/facebook-microblog.service2usr/share/accounts/services/facebook-microblog.service
4usr/share/accounts/providers/facebook.provider3usr/share/accounts/providers/facebook.provider
54
=== modified file 'debian/account-plugin-flickr.install'
--- debian/account-plugin-flickr.install 2014-03-31 08:21:46 +0000
+++ debian/account-plugin-flickr.install 2016-04-05 11:21:38 +0000
@@ -1,4 +1,3 @@
1etc/signon-ui/webkit-options.d/login.yahoo.com.conf
2usr/share/accounts/services/flickr-*.service1usr/share/accounts/services/flickr-*.service
3usr/share/accounts/providers/flickr.provider2usr/share/accounts/providers/flickr.provider
4usr/share/accounts/qml-plugins/flickr/Main.qml3usr/share/accounts/qml-plugins/flickr/Main.qml
54
=== modified file 'debian/account-plugin-twitter.install'
--- debian/account-plugin-twitter.install 2013-06-07 11:56:25 +0000
+++ debian/account-plugin-twitter.install 2016-04-05 11:21:38 +0000
@@ -1,4 +1,3 @@
1etc/signon-ui/webkit-options.d/api.twitter.com.conf
2usr/share/accounts/services/twitter-microblog.service1usr/share/accounts/services/twitter-microblog.service
3usr/share/accounts/providers/twitter.provider2usr/share/accounts/providers/twitter.provider
4usr/share/accounts/qml-plugins/twitter/Main.qml3usr/share/accounts/qml-plugins/twitter/Main.qml
54
=== modified file 'debian/changelog'
--- debian/changelog 2016-01-26 10:52:41 +0000
+++ debian/changelog 2016-04-05 11:21:38 +0000
@@ -1,3 +1,18 @@
1account-plugins (0.13-0ubuntu1) UNRELEASED; urgency=medium
2
3 * After the authentication, retrieve the username in Google, Facebook,
4 Flickr and Twitter plugins (LP: #1565772)
5 * debian/control, debian/libaccount-plugin-facebook.install,
6 debian/libaccount-plugin-flickr.install,
7 debian/libaccount-plugin-twitter.install:
8 add packages containing plugin modules.
9 * debian/account-plugin-facebook.install,
10 debian/account-plugin-flickr.install,
11 debian/account-plugin-twitter.install:
12 remove unneeded webkit-options files.
13
14 -- Alberto Mardegan <alberto.mardegan@canonical.com> Tue, 05 Apr 2016 13:47:48 +0300
15
1account-plugins (0.12+16.04.20160126-0ubuntu1) xenial; urgency=medium16account-plugins (0.12+16.04.20160126-0ubuntu1) xenial; urgency=medium
217
3 [ Alberto Mardegan ]18 [ Alberto Mardegan ]
419
=== modified file 'debian/control'
--- debian/control 2015-07-23 14:10:26 +0000
+++ debian/control 2016-04-05 11:21:38 +0000
@@ -7,9 +7,11 @@
7 gobject-introspection,7 gobject-introspection,
8 python3,8 python3,
9 pkg-config,9 pkg-config,
10 libaccount-plugin-1.0-dev (>= 0.1.9),
10 libaccounts-glib-dev (>= 1.10),11 libaccounts-glib-dev (>= 1.10),
12 libjson-glib-dev,
11 libsignon-glib-dev,13 libsignon-glib-dev,
12 libaccount-plugin-1.0-dev (>= 0.1.3),14 libsoup2.4-dev,
13 valac (>= 0.16),15 valac (>= 0.16),
14 gnome-common,16 gnome-common,
15 dh-autoreconf,17 dh-autoreconf,
@@ -49,26 +51,47 @@
49Description: GNOME Control Center account plugin for single signon51Description: GNOME Control Center account plugin for single signon
50 GNOME Control Center account plugins for single signon52 GNOME Control Center account plugins for single signon
5153
54Package: libaccount-plugin-facebook
55Architecture: any
56Depends: ${shlibs:Depends}, ${misc:Depends},
57 signon-plugin-oauth2,
58Description: GNOME Control Center account plugin for single signon - Facebook Auth
59 GNOME Control Center account plugins for single signon
60
52Package: account-plugin-facebook61Package: account-plugin-facebook
53Architecture: all62Architecture: all
54Depends: ${misc:Depends},63Depends: ${misc:Depends},
55 libaccount-plugin-generic-oauth | ubuntu-system-settings-online-accounts,64 libaccount-plugin-facebook | ubuntu-system-settings-online-accounts,
56 unity-asset-pool (>> 0.8.24daily12.12.05-0ubuntu1),65 unity-asset-pool (>> 0.8.24daily12.12.05-0ubuntu1),
57Description: GNOME Control Center account plugin for single signon - facebook66Description: GNOME Control Center account plugin for single signon - facebook
58 GNOME Control Center account plugins for single signon67 GNOME Control Center account plugins for single signon
5968
69Package: libaccount-plugin-twitter
70Architecture: any
71Depends: ${shlibs:Depends}, ${misc:Depends},
72 signon-plugin-oauth2,
73Description: GNOME Control Center account plugin for single signon - Twitter Auth
74 GNOME Control Center account plugins for single signon
75
60Package: account-plugin-twitter76Package: account-plugin-twitter
61Architecture: all77Architecture: all
62Depends: ${misc:Depends},78Depends: ${misc:Depends},
63 libaccount-plugin-generic-oauth | ubuntu-system-settings-online-accounts,79 libaccount-plugin-twitter | ubuntu-system-settings-online-accounts,
64 unity-asset-pool (>> 0.8.24daily12.12.05-0ubuntu1),80 unity-asset-pool (>> 0.8.24daily12.12.05-0ubuntu1),
65Description: GNOME Control Center account plugin for single signon - twitter81Description: GNOME Control Center account plugin for single signon - twitter
66 GNOME Control Center account plugins for single signon82 GNOME Control Center account plugins for single signon
6783
84Package: libaccount-plugin-flickr
85Architecture: any
86Depends: ${shlibs:Depends}, ${misc:Depends},
87 signon-plugin-oauth2,
88Description: GNOME Control Center account plugin for single signon - Flickr Auth
89 GNOME Control Center account plugins for single signon
90
68Package: account-plugin-flickr91Package: account-plugin-flickr
69Architecture: all92Architecture: all
70Depends: ${misc:Depends},93Depends: ${misc:Depends},
71 libaccount-plugin-generic-oauth | ubuntu-system-settings-online-accounts,94 libaccount-plugin-flickr | ubuntu-system-settings-online-accounts,
72 unity-asset-pool (>> 0.8.24daily12.12.05-0ubuntu1),95 unity-asset-pool (>> 0.8.24daily12.12.05-0ubuntu1),
73Description: GNOME Control Center account plugin for single signon - flickr96Description: GNOME Control Center account plugin for single signon - flickr
74 GNOME Control Center account plugins for single signon97 GNOME Control Center account plugins for single signon
7598
=== added file 'debian/libaccount-plugin-facebook.install'
--- debian/libaccount-plugin-facebook.install 1970-01-01 00:00:00 +0000
+++ debian/libaccount-plugin-facebook.install 2016-04-05 11:21:38 +0000
@@ -0,0 +1,1 @@
1usr/lib/libaccount-plugin-1.0/providers/libfacebook.so
02
=== added file 'debian/libaccount-plugin-flickr.install'
--- debian/libaccount-plugin-flickr.install 1970-01-01 00:00:00 +0000
+++ debian/libaccount-plugin-flickr.install 2016-04-05 11:21:38 +0000
@@ -0,0 +1,1 @@
1usr/lib/libaccount-plugin-1.0/providers/libflickr.so
02
=== added file 'debian/libaccount-plugin-twitter.install'
--- debian/libaccount-plugin-twitter.install 1970-01-01 00:00:00 +0000
+++ debian/libaccount-plugin-twitter.install 2016-04-05 11:21:38 +0000
@@ -0,0 +1,1 @@
1usr/lib/libaccount-plugin-1.0/providers/libtwitter.so
02
=== added file 'src/facebook.vala'
--- src/facebook.vala 1970-01-01 00:00:00 +0000
+++ src/facebook.vala 2016-04-05 11:21:38 +0000
@@ -0,0 +1,69 @@
1/*
2 * Copyright (C) 2016 Canonical, Inc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
16 * USA.
17 *
18 * Authors:
19 * Alberto Mardegan <alberto.mardegan@canonical.com>
20 */
21
22public class FacebookPlugin : Ap.OAuthPlugin {
23 private Soup.Session session;
24
25 public FacebookPlugin (Ag.Account account) {
26 Object (account: account);
27 }
28
29 private void fetch_username (string access_token) {
30 debug ("fetching username, AT = " + access_token);
31 Soup.URI destination_uri =
32 new Soup.URI ("https://graph.facebook.com/me?access_token=" +
33 access_token);
34 var message = new Soup.Message.from_uri ("GET", destination_uri);
35 session = new Soup.Session ();
36 session.queue_message (message, (sess, msg) => {
37 debug ("Got message reply");
38 string body = (string) msg.response_body.data;
39 Json.Parser parser = new Json.Parser ();
40 try {
41 parser.load_from_data (body);
42
43 Json.Node root = parser.get_root ();
44 Json.Object response_object = root.get_object ();
45 var username = response_object.get_string_member ("name");
46 account.set_display_name (username);
47 } catch (Error error) {
48 warning ("Could not parse reply: " + body);
49 }
50
51 store_account ();
52 });
53 }
54
55 protected override void query_username () {
56 var reply = get_oauth_reply ();
57 Variant? v_token = reply.lookup_value ("AccessToken", null);
58 if (v_token != null) {
59 fetch_username (v_token.get_string ());
60 } else {
61 store_account ();
62 }
63 }
64}
65
66public GLib.Type ap_module_get_object_type ()
67{
68 return typeof (FacebookPlugin);
69}
070
=== added file 'src/flickr.vala'
--- src/flickr.vala 1970-01-01 00:00:00 +0000
+++ src/flickr.vala 2016-04-05 11:21:38 +0000
@@ -0,0 +1,41 @@
1/*
2 * Copyright (C) 2016 Canonical, Inc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
16 * USA.
17 *
18 * Authors:
19 * Alberto Mardegan <alberto.mardegan@canonical.com>
20 */
21
22public class FlickrPlugin : Ap.OAuthPlugin {
23 public FlickrPlugin (Ag.Account account) {
24 Object (account: account);
25 }
26
27 protected override void query_username () {
28 var reply = get_oauth_reply ();
29 Variant? v_name = reply.lookup_value ("username", null);
30 if (v_name != null) {
31 account.set_display_name (v_name.get_string ());
32 }
33
34 store_account ();
35 }
36}
37
38public GLib.Type ap_module_get_object_type ()
39{
40 return typeof (FlickrPlugin);
41}
042
=== modified file 'src/google.vala'
--- src/google.vala 2013-06-06 13:16:51 +0000
+++ src/google.vala 2016-04-05 11:21:38 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2012 Canonical, Inc2 * Copyright (C) 2012-2016 Canonical, Inc
3 *3 *
4 * This program is free software; you can redistribute it and/or modify4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as5 * it under the terms of the GNU General Public License version 2 as
@@ -20,6 +20,8 @@
20 */20 */
2121
22public class GooglePlugin : Ap.OAuthPlugin {22public class GooglePlugin : Ap.OAuthPlugin {
23 private Soup.Session session;
24
23 public GooglePlugin (Ag.Account account) {25 public GooglePlugin (Ag.Account account) {
24 Object (account: account);26 Object (account: account);
25 }27 }
@@ -44,6 +46,43 @@
4446
45 set_ignore_cookies (true);47 set_ignore_cookies (true);
46 }48 }
49
50 private void fetch_username (string access_token) {
51 debug ("fetching username, AT = " + access_token);
52 Soup.URI destination_uri =
53 new Soup.URI ("https://www.googleapis.com/oauth2/v3/userinfo");
54 var message = new Soup.Message.from_uri ("POST", destination_uri);
55 message.request_headers.append ("Authorization", "Bearer " + access_token);
56 message.request_headers.set_content_length (0);
57 session = new Soup.Session ();
58 session.queue_message (message, (sess, msg) => {
59 debug ("Got message reply");
60 string body = (string) msg.response_body.data;
61 Json.Parser parser = new Json.Parser ();
62 try {
63 parser.load_from_data (body);
64
65 Json.Node root = parser.get_root ();
66 Json.Object response_object = root.get_object ();
67 var username = response_object.get_string_member ("email");
68 account.set_display_name (username);
69 } catch (Error error) {
70 warning ("Could not parse reply: " + body);
71 }
72
73 store_account ();
74 });
75 }
76
77 protected override void query_username () {
78 var reply = get_oauth_reply ();
79 Variant? v_token = reply.lookup_value ("AccessToken", null);
80 if (v_token != null) {
81 fetch_username (v_token.get_string ());
82 } else {
83 store_account ();
84 }
85 }
47}86}
4887
49public GLib.Type ap_module_get_object_type ()88public GLib.Type ap_module_get_object_type ()
5089
=== added file 'src/twitter.vala'
--- src/twitter.vala 1970-01-01 00:00:00 +0000
+++ src/twitter.vala 2016-04-05 11:21:38 +0000
@@ -0,0 +1,46 @@
1/*
2 * Copyright (C) 2016 Canonical, Inc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
16 * USA.
17 *
18 * Authors:
19 * Alberto Mardegan <alberto.mardegan@canonical.com>
20 */
21
22public class TwitterPlugin : Ap.OAuthPlugin {
23 public TwitterPlugin (Ag.Account account) {
24 Object (account: account);
25 }
26
27 protected override void query_username () {
28 var reply = get_oauth_reply ();
29 Variant? v_name = reply.lookup_value ("ScreenName", null);
30 if (v_name != null) {
31 account.set_display_name (v_name.get_string ());
32 } else {
33 v_name = reply.lookup_value ("UserId", null);
34 if (v_name != null) {
35 account.set_display_name (v_name.get_string ());
36 }
37 }
38
39 store_account ();
40 }
41}
42
43public GLib.Type ap_module_get_object_type ()
44{
45 return typeof (TwitterPlugin);
46}

Subscribers

People subscribed via source and target branches