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

Proposed by Alberto Mardegan on 2016-07-12
Status: Approved
Approved by: David Barth on 2016-08-11
Approved revision: 160
Proposed branch: lp:~mardy/account-plugins/usernames-1565772
Merge into: lp:~online-accounts/account-plugins/16.04
Diff against target: 568 lines (+280/-40)
23 files modified
.bzrignore (+5/-0)
Makefile.am (+26/-7)
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/accounts.google.com.conf (+0/-9)
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-google.install (+0/-1)
debian/account-plugin-twitter.install (+0/-1)
debian/changelog (+16/-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
Online Accounts 2016-07-12 Pending
Review via email: mp+299830@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.
161. By Alberto Mardegan on 2016-12-12

Remove webkit file for google account

162. By Alberto Mardegan on 2016-12-12

Update changelog

Unmerged revisions

162. By Alberto Mardegan on 2016-12-12

Update changelog

161. By Alberto Mardegan on 2016-12-12

Remove webkit file for google account

160. By Alberto Mardegan on 2016-04-05

Changelog

* After the authentication, retrieve the username in Google, Facebook,
  Flickr and Twitter plugins (LP: #1565772)
* debian/control, debian/libaccount-plugin-facebook.install,
  debian/libaccount-plugin-flickr.install,
  debian/libaccount-plugin-twitter.install:
  add packages containing plugin modules.
* debian/account-plugin-facebook.install,
  debian/account-plugin-flickr.install,
  debian/account-plugin-twitter.install:
  remove unneeded webkit-options files.

159. By Alberto Mardegan on 2016-04-05

Fetch username in google plugin

158. By Alberto Mardegan on 2016-04-05

Add plugin for facebook

157. By Alberto Mardegan on 2016-04-05

Create plugin for twitter account

156. By Alberto Mardegan on 2016-04-04

Get username in flickr plugin

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2013-03-19 08:52:34 +0000
3+++ .bzrignore 2016-12-12 08:15:34 +0000
4@@ -6,6 +6,7 @@
5 *.service
6 *.substvars
7 *.stamp
8+*.trs
9 INSTALL
10 Makefile
11 Makefile.in
12@@ -50,7 +51,11 @@
13 .deps
14 .dirstamp
15 .libs
16+/src/facebook.c
17+/src/flickr.c
18 /src/generic-oauth.c
19 /src/google.c
20+/src/twitter.c
21+/test-driver
22 /test-provider
23 /test-service
24
25=== modified file 'Makefile.am'
26--- Makefile.am 2015-04-17 08:53:11 +0000
27+++ Makefile.am 2016-12-12 08:15:34 +0000
28@@ -8,8 +8,11 @@
29 if ENABLE_LIBACCOUNT_PLUGIN
30 # Binary account plugins.
31 plugin_LTLIBRARIES = \
32+ libfacebook.la \
33+ libflickr.la \
34 libgeneric-oauth.la \
35- libgoogle.la
36+ libgoogle.la \
37+ libtwitter.la
38
39 VALAFLAGS = \
40 --vapidir $(top_srcdir)/src \
41@@ -36,12 +39,32 @@
42 -no-undefined \
43 -export-symbols-regex '^ap_module_get_object_type'
44
45-libgoogle_la_CPPFLAGS = $(plugin_cppflags)
46-libgoogle_la_LIBADD = $(plugin_libadd)
47+libfacebook_la_CPPFLAGS = $(plugin_cppflags) $(RESTAPIS_CFLAGS)
48+libfacebook_la_LIBADD = $(plugin_libadd) $(RESTAPIS_LIBS)
49+libfacebook_la_LDFLAGS = $(plugin_ldflags)
50+libfacebook_la_VALAFLAGS = --pkg libsoup-2.4 --pkg json-glib-1.0
51+libfacebook_la_SOURCES = \
52+ src/facebook.vala
53+
54+libflickr_la_CPPFLAGS = $(plugin_cppflags)
55+libflickr_la_LIBADD = $(plugin_libadd)
56+libflickr_la_LDFLAGS = $(plugin_ldflags)
57+libflickr_la_SOURCES = \
58+ src/flickr.vala
59+
60+libgoogle_la_CPPFLAGS = $(plugin_cppflags) $(RESTAPIS_CFLAGS)
61+libgoogle_la_LIBADD = $(plugin_libadd) $(RESTAPIS_LIBS)
62 libgoogle_la_LDFLAGS = $(plugin_ldflags)
63+libgoogle_la_VALAFLAGS = --pkg libsoup-2.4 --pkg json-glib-1.0
64 libgoogle_la_SOURCES = \
65 src/google.vala
66
67+libtwitter_la_CPPFLAGS = $(plugin_cppflags)
68+libtwitter_la_LIBADD = $(plugin_libadd)
69+libtwitter_la_LDFLAGS = $(plugin_ldflags)
70+libtwitter_la_SOURCES = \
71+ src/twitter.vala
72+
73 libgeneric_oauth_la_CPPFLAGS = $(plugin_cppflags)
74 libgeneric_oauth_la_LIBADD = $(plugin_libadd)
75 libgeneric_oauth_la_LDFLAGS = $(plugin_ldflags)
76@@ -100,16 +123,12 @@
77
78 webkitoptionsdir = $(sysconfdir)/signon-ui/webkit-options.d
79 dist_webkitoptions_DATA = \
80- data/webkit-options/accounts.google.com.conf \
81 data/webkit-options/api.instagram.com.conf \
82 data/webkit-options/api.weibo.com.conf \
83 data/webkit-options/api.t.sohu.com.conf \
84- data/webkit-options/api.twitter.com.conf \
85 data/webkit-options/foursquare.com.conf \
86 data/webkit-options/identi.ca.conf \
87 data/webkit-options/login.live.com.conf \
88- data/webkit-options/login.yahoo.com.conf \
89- data/webkit-options/www.facebook.com.conf \
90 data/webkit-options/www.linkedin.com.conf
91
92 dist_bin_SCRIPTS = \
93
94=== modified file 'configure.ac'
95--- configure.ac 2014-09-11 10:07:28 +0000
96+++ configure.ac 2016-12-12 08:15:34 +0000
97@@ -41,7 +41,10 @@
98 [have_libaccount_plugin=no])
99
100 AS_IF([test "x$have_libaccount_plugin" = "xyes"],
101- [PKG_CHECK_MODULES([ACCOUNT_PLUGINS], [account-plugin >= 0.1.3])],
102+ [
103+ PKG_CHECK_MODULES([ACCOUNT_PLUGINS], [account-plugin >= 0.1.3])
104+ PKG_CHECK_MODULES([RESTAPIS], [libsoup-2.4 json-glib-1.0])
105+ ],
106 [AS_IF([test "x$enable_libaccount_plugin" = "xyes"],
107 [AC_MSG_ERROR([libaccount-plugin support enabled but required dependencies were not found])])])
108
109
110=== modified file 'data/providers/facebook.provider.in.in'
111--- data/providers/facebook.provider.in.in 2015-09-09 08:48:32 +0000
112+++ data/providers/facebook.provider.in.in 2016-12-12 08:15:34 +0000
113@@ -4,7 +4,7 @@
114 <icon>facebook</icon>
115 <translations>account-plugins</translations>
116 <domains>.*facebook\.com</domains>
117- <plugin>generic-oauth</plugin>
118+ <plugin>facebook</plugin>
119 <single-account>true</single-account>
120
121 <template>
122
123=== modified file 'data/providers/flickr.provider.in.in'
124--- data/providers/flickr.provider.in.in 2013-02-25 06:25:34 +0000
125+++ data/providers/flickr.provider.in.in 2016-12-12 08:15:34 +0000
126@@ -4,7 +4,7 @@
127 <icon>flickr</icon>
128 <translations>account-plugins</translations>
129 <domains>.*flickr\.com</domains>
130- <plugin>generic-oauth</plugin>
131+ <plugin>flickr</plugin>
132
133 <template>
134 <group name="auth">
135
136=== modified file 'data/providers/twitter.provider.in.in'
137--- data/providers/twitter.provider.in.in 2013-02-22 15:17:49 +0000
138+++ data/providers/twitter.provider.in.in 2016-12-12 08:15:34 +0000
139@@ -3,7 +3,7 @@
140 <name>Twitter</name>
141 <icon>twitter</icon>
142 <translations>account-plugins</translations>
143- <plugin>generic-oauth</plugin>
144+ <plugin>twitter</plugin>
145 <domains>.*twitter\.com</domains>
146
147 <template>
148
149=== removed file 'data/webkit-options/accounts.google.com.conf'
150--- data/webkit-options/accounts.google.com.conf 2012-11-09 11:11:43 +0000
151+++ data/webkit-options/accounts.google.com.conf 1970-01-01 00:00:00 +0000
152@@ -1,9 +0,0 @@
153-ViewportWidth = 480
154-ViewportHeight = 420
155-UsernameField = input[name="Email"]
156-PasswordField = input[name="Passwd"]
157-# Accept all https URLs, and add as exceptions those http only
158-# URLs which are used in some countries.
159-# See https://bugs.launchpad.net/bugs/1074733
160-AllowedUrls = (https://.*|http://[^/]*google\\.[^.]+/accounts/.*)
161-
162
163=== removed file 'data/webkit-options/api.twitter.com.conf'
164--- data/webkit-options/api.twitter.com.conf 2012-06-19 06:08:30 +0000
165+++ data/webkit-options/api.twitter.com.conf 1970-01-01 00:00:00 +0000
166@@ -1,2 +0,0 @@
167-UsernameField = input[id="username_or_email"]
168-PasswordField = input[id="password"]
169
170=== removed file 'data/webkit-options/login.yahoo.com.conf'
171--- data/webkit-options/login.yahoo.com.conf 2012-06-18 14:24:03 +0000
172+++ data/webkit-options/login.yahoo.com.conf 1970-01-01 00:00:00 +0000
173@@ -1,2 +0,0 @@
174-UsernameField = input[name="login"]
175-PasswordField = input[name="passwd"]
176
177=== removed file 'data/webkit-options/www.facebook.com.conf'
178--- data/webkit-options/www.facebook.com.conf 2012-05-02 22:58:29 +0000
179+++ data/webkit-options/www.facebook.com.conf 1970-01-01 00:00:00 +0000
180@@ -1,7 +0,0 @@
181-ViewportWidth = 420
182-ViewportHeight = 320
183-UsernameField = input[name="email"]
184-PasswordField = input[name="pass"]
185-#ZoomFactor = 2
186-#PreferredWidth = 420
187-
188
189=== modified file 'debian/account-plugin-facebook.install'
190--- debian/account-plugin-facebook.install 2015-04-17 08:53:11 +0000
191+++ debian/account-plugin-facebook.install 2016-12-12 08:15:34 +0000
192@@ -1,4 +1,3 @@
193-etc/signon-ui/webkit-options.d/www.facebook.com.conf
194 usr/share/accounts/services/facebook-sharing.service
195 usr/share/accounts/services/facebook-microblog.service
196 usr/share/accounts/providers/facebook.provider
197
198=== modified file 'debian/account-plugin-flickr.install'
199--- debian/account-plugin-flickr.install 2014-03-31 08:21:46 +0000
200+++ debian/account-plugin-flickr.install 2016-12-12 08:15:34 +0000
201@@ -1,4 +1,3 @@
202-etc/signon-ui/webkit-options.d/login.yahoo.com.conf
203 usr/share/accounts/services/flickr-*.service
204 usr/share/accounts/providers/flickr.provider
205 usr/share/accounts/qml-plugins/flickr/Main.qml
206
207=== modified file 'debian/account-plugin-google.install'
208--- debian/account-plugin-google.install 2013-08-01 14:34:21 +0000
209+++ debian/account-plugin-google.install 2016-12-12 08:15:34 +0000
210@@ -1,4 +1,3 @@
211-etc/signon-ui/webkit-options.d/accounts.google.com.conf
212 usr/share/accounts/services/google-drive.service
213 usr/share/accounts/services/google-im.service
214 usr/share/accounts/services/picasa.service
215
216=== modified file 'debian/account-plugin-twitter.install'
217--- debian/account-plugin-twitter.install 2013-06-07 11:56:25 +0000
218+++ debian/account-plugin-twitter.install 2016-12-12 08:15:34 +0000
219@@ -1,4 +1,3 @@
220-etc/signon-ui/webkit-options.d/api.twitter.com.conf
221 usr/share/accounts/services/twitter-microblog.service
222 usr/share/accounts/providers/twitter.provider
223 usr/share/accounts/qml-plugins/twitter/Main.qml
224
225=== modified file 'debian/changelog'
226--- debian/changelog 2016-01-26 10:52:41 +0000
227+++ debian/changelog 2016-12-12 08:15:34 +0000
228@@ -1,3 +1,19 @@
229+account-plugins (0.13-0ubuntu1) UNRELEASED; urgency=medium
230+
231+ * After the authentication, retrieve the username in Google, Facebook,
232+ Flickr and Twitter plugins (LP: #1565772)
233+ * debian/control, debian/libaccount-plugin-facebook.install,
234+ debian/libaccount-plugin-flickr.install,
235+ debian/libaccount-plugin-twitter.install:
236+ add packages containing plugin modules.
237+ * debian/account-plugin-facebook.install,
238+ debian/account-plugin-flickr.install,
239+ debian/account-plugin-google.install,
240+ debian/account-plugin-twitter.install:
241+ remove unneeded webkit-options files.
242+
243+ -- Alberto Mardegan <alberto.mardegan@canonical.com> Tue, 05 Apr 2016 13:47:48 +0300
244+
245 account-plugins (0.12+16.04.20160126-0ubuntu1) xenial; urgency=medium
246
247 [ Alberto Mardegan ]
248
249=== modified file 'debian/control'
250--- debian/control 2015-07-23 14:10:26 +0000
251+++ debian/control 2016-12-12 08:15:34 +0000
252@@ -7,9 +7,11 @@
253 gobject-introspection,
254 python3,
255 pkg-config,
256+ libaccount-plugin-1.0-dev (>= 0.1.9),
257 libaccounts-glib-dev (>= 1.10),
258+ libjson-glib-dev,
259 libsignon-glib-dev,
260- libaccount-plugin-1.0-dev (>= 0.1.3),
261+ libsoup2.4-dev,
262 valac (>= 0.16),
263 gnome-common,
264 dh-autoreconf,
265@@ -49,26 +51,47 @@
266 Description: GNOME Control Center account plugin for single signon
267 GNOME Control Center account plugins for single signon
268
269+Package: libaccount-plugin-facebook
270+Architecture: any
271+Depends: ${shlibs:Depends}, ${misc:Depends},
272+ signon-plugin-oauth2,
273+Description: GNOME Control Center account plugin for single signon - Facebook Auth
274+ GNOME Control Center account plugins for single signon
275+
276 Package: account-plugin-facebook
277 Architecture: all
278 Depends: ${misc:Depends},
279- libaccount-plugin-generic-oauth | ubuntu-system-settings-online-accounts,
280+ libaccount-plugin-facebook | ubuntu-system-settings-online-accounts,
281 unity-asset-pool (>> 0.8.24daily12.12.05-0ubuntu1),
282 Description: GNOME Control Center account plugin for single signon - facebook
283 GNOME Control Center account plugins for single signon
284
285+Package: libaccount-plugin-twitter
286+Architecture: any
287+Depends: ${shlibs:Depends}, ${misc:Depends},
288+ signon-plugin-oauth2,
289+Description: GNOME Control Center account plugin for single signon - Twitter Auth
290+ GNOME Control Center account plugins for single signon
291+
292 Package: account-plugin-twitter
293 Architecture: all
294 Depends: ${misc:Depends},
295- libaccount-plugin-generic-oauth | ubuntu-system-settings-online-accounts,
296+ libaccount-plugin-twitter | ubuntu-system-settings-online-accounts,
297 unity-asset-pool (>> 0.8.24daily12.12.05-0ubuntu1),
298 Description: GNOME Control Center account plugin for single signon - twitter
299 GNOME Control Center account plugins for single signon
300
301+Package: libaccount-plugin-flickr
302+Architecture: any
303+Depends: ${shlibs:Depends}, ${misc:Depends},
304+ signon-plugin-oauth2,
305+Description: GNOME Control Center account plugin for single signon - Flickr Auth
306+ GNOME Control Center account plugins for single signon
307+
308 Package: account-plugin-flickr
309 Architecture: all
310 Depends: ${misc:Depends},
311- libaccount-plugin-generic-oauth | ubuntu-system-settings-online-accounts,
312+ libaccount-plugin-flickr | ubuntu-system-settings-online-accounts,
313 unity-asset-pool (>> 0.8.24daily12.12.05-0ubuntu1),
314 Description: GNOME Control Center account plugin for single signon - flickr
315 GNOME Control Center account plugins for single signon
316
317=== added file 'debian/libaccount-plugin-facebook.install'
318--- debian/libaccount-plugin-facebook.install 1970-01-01 00:00:00 +0000
319+++ debian/libaccount-plugin-facebook.install 2016-12-12 08:15:34 +0000
320@@ -0,0 +1,1 @@
321+usr/lib/libaccount-plugin-1.0/providers/libfacebook.so
322
323=== added file 'debian/libaccount-plugin-flickr.install'
324--- debian/libaccount-plugin-flickr.install 1970-01-01 00:00:00 +0000
325+++ debian/libaccount-plugin-flickr.install 2016-12-12 08:15:34 +0000
326@@ -0,0 +1,1 @@
327+usr/lib/libaccount-plugin-1.0/providers/libflickr.so
328
329=== added file 'debian/libaccount-plugin-twitter.install'
330--- debian/libaccount-plugin-twitter.install 1970-01-01 00:00:00 +0000
331+++ debian/libaccount-plugin-twitter.install 2016-12-12 08:15:34 +0000
332@@ -0,0 +1,1 @@
333+usr/lib/libaccount-plugin-1.0/providers/libtwitter.so
334
335=== added file 'src/facebook.vala'
336--- src/facebook.vala 1970-01-01 00:00:00 +0000
337+++ src/facebook.vala 2016-12-12 08:15:34 +0000
338@@ -0,0 +1,69 @@
339+/*
340+ * Copyright (C) 2016 Canonical, Inc
341+ *
342+ * This program is free software; you can redistribute it and/or modify
343+ * it under the terms of the GNU General Public License version 2 as
344+ * published by the Free Software Foundation.
345+ *
346+ * This program is distributed in the hope that it will be useful,
347+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
348+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
349+ * GNU General Public License for more details.
350+ *
351+ * You should have received a copy of the GNU General Public License
352+ * along with this program; if not, write to the Free Software
353+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
354+ * USA.
355+ *
356+ * Authors:
357+ * Alberto Mardegan <alberto.mardegan@canonical.com>
358+ */
359+
360+public class FacebookPlugin : Ap.OAuthPlugin {
361+ private Soup.Session session;
362+
363+ public FacebookPlugin (Ag.Account account) {
364+ Object (account: account);
365+ }
366+
367+ private void fetch_username (string access_token) {
368+ debug ("fetching username, AT = " + access_token);
369+ Soup.URI destination_uri =
370+ new Soup.URI ("https://graph.facebook.com/me?access_token=" +
371+ access_token);
372+ var message = new Soup.Message.from_uri ("GET", destination_uri);
373+ session = new Soup.Session ();
374+ session.queue_message (message, (sess, msg) => {
375+ debug ("Got message reply");
376+ string body = (string) msg.response_body.data;
377+ Json.Parser parser = new Json.Parser ();
378+ try {
379+ parser.load_from_data (body);
380+
381+ Json.Node root = parser.get_root ();
382+ Json.Object response_object = root.get_object ();
383+ var username = response_object.get_string_member ("name");
384+ account.set_display_name (username);
385+ } catch (Error error) {
386+ warning ("Could not parse reply: " + body);
387+ }
388+
389+ store_account ();
390+ });
391+ }
392+
393+ protected override void query_username () {
394+ var reply = get_oauth_reply ();
395+ Variant? v_token = reply.lookup_value ("AccessToken", null);
396+ if (v_token != null) {
397+ fetch_username (v_token.get_string ());
398+ } else {
399+ store_account ();
400+ }
401+ }
402+}
403+
404+public GLib.Type ap_module_get_object_type ()
405+{
406+ return typeof (FacebookPlugin);
407+}
408
409=== added file 'src/flickr.vala'
410--- src/flickr.vala 1970-01-01 00:00:00 +0000
411+++ src/flickr.vala 2016-12-12 08:15:34 +0000
412@@ -0,0 +1,41 @@
413+/*
414+ * Copyright (C) 2016 Canonical, Inc
415+ *
416+ * This program is free software; you can redistribute it and/or modify
417+ * it under the terms of the GNU General Public License version 2 as
418+ * published by the Free Software Foundation.
419+ *
420+ * This program is distributed in the hope that it will be useful,
421+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
422+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
423+ * GNU General Public License for more details.
424+ *
425+ * You should have received a copy of the GNU General Public License
426+ * along with this program; if not, write to the Free Software
427+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
428+ * USA.
429+ *
430+ * Authors:
431+ * Alberto Mardegan <alberto.mardegan@canonical.com>
432+ */
433+
434+public class FlickrPlugin : Ap.OAuthPlugin {
435+ public FlickrPlugin (Ag.Account account) {
436+ Object (account: account);
437+ }
438+
439+ protected override void query_username () {
440+ var reply = get_oauth_reply ();
441+ Variant? v_name = reply.lookup_value ("username", null);
442+ if (v_name != null) {
443+ account.set_display_name (v_name.get_string ());
444+ }
445+
446+ store_account ();
447+ }
448+}
449+
450+public GLib.Type ap_module_get_object_type ()
451+{
452+ return typeof (FlickrPlugin);
453+}
454
455=== modified file 'src/google.vala'
456--- src/google.vala 2013-06-06 13:16:51 +0000
457+++ src/google.vala 2016-12-12 08:15:34 +0000
458@@ -1,5 +1,5 @@
459 /*
460- * Copyright (C) 2012 Canonical, Inc
461+ * Copyright (C) 2012-2016 Canonical, Inc
462 *
463 * This program is free software; you can redistribute it and/or modify
464 * it under the terms of the GNU General Public License version 2 as
465@@ -20,6 +20,8 @@
466 */
467
468 public class GooglePlugin : Ap.OAuthPlugin {
469+ private Soup.Session session;
470+
471 public GooglePlugin (Ag.Account account) {
472 Object (account: account);
473 }
474@@ -44,6 +46,43 @@
475
476 set_ignore_cookies (true);
477 }
478+
479+ private void fetch_username (string access_token) {
480+ debug ("fetching username, AT = " + access_token);
481+ Soup.URI destination_uri =
482+ new Soup.URI ("https://www.googleapis.com/oauth2/v3/userinfo");
483+ var message = new Soup.Message.from_uri ("POST", destination_uri);
484+ message.request_headers.append ("Authorization", "Bearer " + access_token);
485+ message.request_headers.set_content_length (0);
486+ session = new Soup.Session ();
487+ session.queue_message (message, (sess, msg) => {
488+ debug ("Got message reply");
489+ string body = (string) msg.response_body.data;
490+ Json.Parser parser = new Json.Parser ();
491+ try {
492+ parser.load_from_data (body);
493+
494+ Json.Node root = parser.get_root ();
495+ Json.Object response_object = root.get_object ();
496+ var username = response_object.get_string_member ("email");
497+ account.set_display_name (username);
498+ } catch (Error error) {
499+ warning ("Could not parse reply: " + body);
500+ }
501+
502+ store_account ();
503+ });
504+ }
505+
506+ protected override void query_username () {
507+ var reply = get_oauth_reply ();
508+ Variant? v_token = reply.lookup_value ("AccessToken", null);
509+ if (v_token != null) {
510+ fetch_username (v_token.get_string ());
511+ } else {
512+ store_account ();
513+ }
514+ }
515 }
516
517 public GLib.Type ap_module_get_object_type ()
518
519=== added file 'src/twitter.vala'
520--- src/twitter.vala 1970-01-01 00:00:00 +0000
521+++ src/twitter.vala 2016-12-12 08:15:34 +0000
522@@ -0,0 +1,46 @@
523+/*
524+ * Copyright (C) 2016 Canonical, Inc
525+ *
526+ * This program is free software; you can redistribute it and/or modify
527+ * it under the terms of the GNU General Public License version 2 as
528+ * published by the Free Software Foundation.
529+ *
530+ * This program is distributed in the hope that it will be useful,
531+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
532+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
533+ * GNU General Public License for more details.
534+ *
535+ * You should have received a copy of the GNU General Public License
536+ * along with this program; if not, write to the Free Software
537+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
538+ * USA.
539+ *
540+ * Authors:
541+ * Alberto Mardegan <alberto.mardegan@canonical.com>
542+ */
543+
544+public class TwitterPlugin : Ap.OAuthPlugin {
545+ public TwitterPlugin (Ag.Account account) {
546+ Object (account: account);
547+ }
548+
549+ protected override void query_username () {
550+ var reply = get_oauth_reply ();
551+ Variant? v_name = reply.lookup_value ("ScreenName", null);
552+ if (v_name != null) {
553+ account.set_display_name (v_name.get_string ());
554+ } else {
555+ v_name = reply.lookup_value ("UserId", null);
556+ if (v_name != null) {
557+ account.set_display_name (v_name.get_string ());
558+ }
559+ }
560+
561+ store_account ();
562+ }
563+}
564+
565+public GLib.Type ap_module_get_object_type ()
566+{
567+ return typeof (TwitterPlugin);
568+}

Subscribers

People subscribed via source and target branches