Merge lp:~mardy/gnome-control-center-signon/username-1565772 into lp:gnome-control-center-signon

Proposed by Alberto Mardegan
Status: Merged
Approved by: David Barth
Approved revision: 187
Merged at revision: 184
Proposed branch: lp:~mardy/gnome-control-center-signon/username-1565772
Merge into: lp:gnome-control-center-signon
Diff against target: 250 lines (+65/-24)
5 files modified
debian/changelog (+8/-0)
debian/libaccount-plugin-1.0-0.symbols (+2/-0)
libaccount-plugin/AccountPlugin.vapi (+3/-0)
libaccount-plugin/oauth-plugin.c (+49/-23)
libaccount-plugin/oauth-plugin.h (+3/-1)
To merge this branch: bzr merge lp:~mardy/gnome-control-center-signon/username-1565772
Reviewer Review Type Date Requested Status
Online Accounts Pending
Review via email: mp+290966@code.launchpad.net

Commit message

Allow OAuth-based account plugins to override display name

Add a virtual method to allow account plugins to retrieve the user name, typically via REST API calls to the remote service. This will allow us to get rid of the ugly hack in signon-ui, where we retrieve the username by inspecting the DOM of the webpages.

Description of the change

Allow OAuth-based account plugins to override display name

Add a virtual method to allow account plugins to retrieve the user name, typically via REST API calls to the remote service. This will allow us to get rid of the ugly hack in signon-ui, where we retrieve the username by inspecting the DOM of the webpages.

To post a comment you must log in.
187. By Alberto Mardegan

formatting

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2016-02-01 12:38:02 +0000
3+++ debian/changelog 2016-04-05 11:23:59 +0000
4@@ -1,3 +1,11 @@
5+gnome-control-center-signon (0.1.9-0ubuntu1) UNRELEASED; urgency=medium
6+
7+ * Allow plugins to retrieve username (LP: #1565772)
8+ * debian/libaccount-plugin-1.0-0.symbols
9+ - new symbols
10+
11+ -- Alberto Mardegan <alberto.mardegan@canonical.com> Mon, 04 Apr 2016 16:59:39 +0300
12+
13 gnome-control-center-signon (0.1.8+16.04.20160201-0ubuntu1) xenial; urgency=medium
14
15 [ CI Train Bot ]
16
17=== modified file 'debian/libaccount-plugin-1.0-0.symbols'
18--- debian/libaccount-plugin-1.0-0.symbols 2015-12-08 10:10:04 +0000
19+++ debian/libaccount-plugin-1.0-0.symbols 2016-04-05 11:23:59 +0000
20@@ -9,10 +9,12 @@
21 ap_client_has_plugin@Base 0.1.8
22 ap_client_load_application_plugin@Base 0.0.2
23 ap_client_load_plugin@Base 0.0.1
24+ ap_oauth_plugin_get_oauth_reply@Base 0.1.9
25 ap_oauth_plugin_get_type@Base 0.0.1
26 ap_oauth_plugin_set_account_oauth_parameters@Base 0.0.9+r86
27 ap_oauth_plugin_set_mechanism@Base 0.0.6
28 ap_oauth_plugin_set_oauth_parameters@Base 0.0.1
29+ ap_oauth_plugin_store_account@Base 0.1.9
30 ap_plugin_act_headless@Base 0.0.4
31 ap_plugin_build_widget@Base 0.0.1
32 ap_plugin_delete_account@Base 0.0.2
33
34=== modified file 'libaccount-plugin/AccountPlugin.vapi'
35--- libaccount-plugin/AccountPlugin.vapi 2015-12-02 14:18:42 +0000
36+++ libaccount-plugin/AccountPlugin.vapi 2016-04-05 11:23:59 +0000
37@@ -23,6 +23,9 @@
38 public void set_mechanism (Ap.OAuthMechanism mechanism);
39 public void set_oauth_parameters (GLib.HashTable<string,GLib.Value?> oauth_params);
40 public void set_account_oauth_parameters (GLib.HashTable<string,GLib.Value?> oauth_params);
41+ public unowned GLib.Variant get_oauth_reply ();
42+ protected virtual void query_username ();
43+ protected void store_account ();
44 [NoAccessorMethod]
45 public GLib.HashTable<weak void*,weak void*> oauth_params { owned get; construct; }
46 }
47
48=== modified file 'libaccount-plugin/oauth-plugin.c'
49--- libaccount-plugin/oauth-plugin.c 2013-05-07 12:26:23 +0000
50+++ libaccount-plugin/oauth-plugin.c 2016-04-05 11:23:59 +0000
51@@ -60,6 +60,7 @@
52 SignonAuthSession *auth_session;
53 GDBusConnection *connection;
54 GCancellable *cancellable;
55+ GVariant *oauth_reply;
56 gboolean identity_stored;
57 gboolean deleting_identity;
58 gboolean authenticating;
59@@ -265,13 +266,6 @@
60 gpointer key, value;
61 gchar *full_key;
62 const gchar *mechanism;
63- const gchar *username;
64-
65- username = ap_plugin_get_username ((ApPlugin *)self);
66- if (username != NULL)
67- {
68- ag_account_set_display_name (account, username);
69- }
70
71 mechanism = get_mechanism (priv);
72 /* Delete any existing parameter (if the account is not new) */
73@@ -298,8 +292,16 @@
74 }
75 }
76
77-static void
78-store_account (ApOAuthPlugin *self)
79+/**
80+ * ap_oauth_plugin_store_account:
81+ * @self: the #ApOAuthPlugin.
82+ *
83+ * Store the account into the database. Subclasses which reimplemented the
84+ * query_username() method should call this protected method after they are
85+ * done.
86+ */
87+void
88+ap_oauth_plugin_store_account (ApOAuthPlugin *self)
89 {
90 AgAccount *account;
91
92@@ -318,6 +320,7 @@
93 gpointer user_data)
94 {
95 ApOAuthPlugin *self = AP_OAUTH_PLUGIN (user_data);
96+ AgAccount *account;
97
98 if (G_UNLIKELY (error != NULL))
99 {
100@@ -331,14 +334,16 @@
101 if (username != NULL)
102 {
103 ap_plugin_set_credentials ((ApPlugin *)self, username, NULL);
104+ account = ap_plugin_get_account ((ApPlugin *)self);
105+ ag_account_set_display_name (account, username);
106 }
107 }
108
109- store_account (self);
110+ ap_oauth_plugin_store_account (self);
111 }
112
113 static void
114-query_username (ApOAuthPlugin *self)
115+_ap_oauth_plugin_query_username (ApOAuthPlugin *self)
116 {
117 ApOAuthPluginPrivate *priv = self->priv;
118
119@@ -353,17 +358,12 @@
120 ApOAuthPlugin *self;
121 SignonAuthSession *auth_session = SIGNON_AUTH_SESSION (source_object);
122 AgAccount *account;
123- GVariant *session_data;
124+ GVariant *oauth_reply;
125 GError *error = NULL;
126
127- session_data = signon_auth_session_process_finish (auth_session,
128- res,
129- &error);
130- if (session_data != NULL)
131- {
132- /* We don't care about the response */
133- g_variant_unref (session_data);
134- }
135+ oauth_reply = signon_auth_session_process_finish (auth_session,
136+ res,
137+ &error);
138
139 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
140 {
141@@ -373,6 +373,7 @@
142
143 self = AP_OAUTH_PLUGIN (user_data);
144 self->priv->authenticating = FALSE;
145+ self->priv->oauth_reply = oauth_reply;
146
147 if (G_UNLIKELY (error != NULL))
148 {
149@@ -397,7 +398,7 @@
150 if (account->id == 0)
151 {
152 /* newly created account */
153- query_username (self);
154+ AP_OAUTH_PLUGIN_GET_CLASS (self)->query_username (self);
155 }
156 else
157 {
158@@ -408,7 +409,7 @@
159 * This might be removed or reviewed once the following is implemented:
160 * http://code.google.com/p/accounts-sso/issues/detail?id=111
161 */
162- store_account (self);
163+ ap_oauth_plugin_store_account (self);
164 }
165 }
166
167@@ -541,7 +542,7 @@
168 else
169 {
170 /* operating headless: just store the account */
171- store_account (self);
172+ ap_oauth_plugin_store_account (self);
173 }
174 }
175
176@@ -778,6 +779,7 @@
177 ApOAuthPluginPrivate);
178 self->priv->mechanism = NULL;
179 self->priv->cancellable = g_cancellable_new ();
180+ self->priv->oauth_reply = NULL;
181 }
182
183 static void
184@@ -875,6 +877,12 @@
185 priv->cancellable = NULL;
186 }
187
188+ if (priv->oauth_reply)
189+ {
190+ g_variant_unref (priv->oauth_reply);
191+ priv->oauth_reply = NULL;
192+ }
193+
194 g_clear_object (&priv->connection);
195
196 G_OBJECT_CLASS (ap_oauth_plugin_parent_class)->dispose (object);
197@@ -976,6 +984,7 @@
198 plugin_class->build_widget = ap_oauth_plugin_build_widget;
199 plugin_class->act_headless = ap_oauth_plugin_act_headless;
200
201+ klass->query_username = _ap_oauth_plugin_query_username;
202 /**
203 * ApOAuthPlugin:oauth-params:
204 *
205@@ -1035,6 +1044,23 @@
206 }
207
208 /**
209+ * ap_oauth_plugin_get_oauth_reply:
210+ * @self: the #ApOAuthPlugin.
211+ *
212+ * Get the authentication reply.
213+ *
214+ * Returns: (transfer none): the dictionary of OAuth reply parameters returned
215+ * by the authentication plugin.
216+ */
217+GVariant *
218+ap_oauth_plugin_get_oauth_reply (ApOAuthPlugin *self)
219+{
220+ g_return_val_if_fail (AP_IS_OAUTH_PLUGIN (self), NULL);
221+
222+ return self->priv->oauth_reply;
223+}
224+
225+/**
226 * ap_oauth_plugin_set_mechanism:
227 * @self: the #ApOAuthPlugin.
228 * @mechanism: the desired OAuth mechanism.
229
230=== modified file 'libaccount-plugin/oauth-plugin.h'
231--- libaccount-plugin/oauth-plugin.h 2012-07-18 08:06:52 +0000
232+++ libaccount-plugin/oauth-plugin.h 2016-04-05 11:23:59 +0000
233@@ -46,7 +46,7 @@
234 struct _ApOAuthPluginClass
235 {
236 ApPluginClass parent_class;
237- void (*_ap_reserved1) (void);
238+ void (*query_username) (ApOAuthPlugin *self);
239 void (*_ap_reserved2) (void);
240 void (*_ap_reserved3) (void);
241 void (*_ap_reserved4) (void);
242@@ -74,6 +74,8 @@
243 GHashTable *oauth_params);
244 void ap_oauth_plugin_set_account_oauth_parameters (ApOAuthPlugin *self,
245 GHashTable *oauth_params);
246+GVariant *ap_oauth_plugin_get_oauth_reply (ApOAuthPlugin *self);
247+void ap_oauth_plugin_store_account (ApOAuthPlugin *self);
248
249 /**
250 * ApOAuthMechanism:

Subscribers

People subscribed via source and target branches