aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorDebarshi Ray <debarshir@src.gnome.org>2012-11-06 05:40:50 +0800
committerDebarshi Ray <debarshir@gnome.org>2012-11-09 19:00:34 +0800
commitd84aede9b551389a5fa39bdba55779a6c6f66f6e (patch)
treece9e079d39b74f222b160e757892f65002556089 /libempathy
parentfdb8845d0b1bb476cc82bc1efc2214015e3a3730 (diff)
downloadgsoc2013-empathy-d84aede9b551389a5fa39bdba55779a6c6f66f6e.tar
gsoc2013-empathy-d84aede9b551389a5fa39bdba55779a6c6f66f6e.tar.gz
gsoc2013-empathy-d84aede9b551389a5fa39bdba55779a6c6f66f6e.tar.bz2
gsoc2013-empathy-d84aede9b551389a5fa39bdba55779a6c6f66f6e.tar.lz
gsoc2013-empathy-d84aede9b551389a5fa39bdba55779a6c6f66f6e.tar.xz
gsoc2013-empathy-d84aede9b551389a5fa39bdba55779a6c6f66f6e.tar.zst
gsoc2013-empathy-d84aede9b551389a5fa39bdba55779a6c6f66f6e.zip
auth-client: Support X-TELEPATHY-PASSWORD for GOA accounts
If a provider supports more than one authentication mechanism (eg., Google), we prefer OAuth2. Fixes: https://bugzilla.gnome.org/687690
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-goa-auth-handler.c67
1 files changed, 57 insertions, 10 deletions
diff --git a/libempathy/empathy-goa-auth-handler.c b/libempathy/empathy-goa-auth-handler.c
index 49fc96270..db37eab54 100644
--- a/libempathy/empathy-goa-auth-handler.c
+++ b/libempathy/empathy-goa-auth-handler.c
@@ -196,6 +196,31 @@ got_oauth2_access_token_cb (GObject *source,
}
static void
+got_password_passwd_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GoaPasswordBased *password = (GoaPasswordBased *) source;
+ AuthData *data = user_data;
+ gchar *passwd;
+ GError *error = NULL;
+
+ if (!goa_password_based_call_get_password_finish (password,
+ &passwd, result, &error))
+ {
+ DEBUG ("Failed to get password: %s", error->message);
+ fail_auth (data);
+ g_clear_error (&error);
+ return;
+ }
+
+ DEBUG ("Got password for %s", tp_proxy_get_object_path (data->account));
+
+ empathy_sasl_auth_password_async (data->channel, passwd, auth_cb, data);
+ g_free (passwd);
+}
+
+static void
ensure_credentials_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
@@ -203,6 +228,9 @@ ensure_credentials_cb (GObject *source,
AuthData *data = user_data;
GoaAccount *goa_account = (GoaAccount *) source;
GoaOAuth2Based *oauth2;
+ GoaPasswordBased *password;
+ EmpathySaslMechanism mech;
+ gboolean supports_password;
gint expires_in;
GError *error = NULL;
@@ -215,22 +243,40 @@ ensure_credentials_cb (GObject *source,
return;
}
- /* We support only oaut2 */
+ /* We prefer oauth2, if available */
oauth2 = goa_object_get_oauth2_based (data->goa_object);
- if (oauth2 == NULL)
+ mech = empathy_sasl_channel_select_mechanism (data->channel);
+ if (oauth2 != NULL && mech != EMPATHY_SASL_MECHANISM_PASSWORD)
{
- DEBUG ("GoaObject does not implement oauth2");
- fail_auth (data);
+ DEBUG ("Goa daemon has credentials for %s, get the access token",
+ tp_proxy_get_object_path (data->account));
+
+ goa_oauth2_based_call_get_access_token (oauth2, NULL,
+ got_oauth2_access_token_cb, data);
+
+ g_object_unref (oauth2);
return;
}
- DEBUG ("Goa daemon has credentials for %s, get the access token",
- tp_proxy_get_object_path (data->account));
+ /* Else we use the password */
+ password = goa_object_get_password_based (data->goa_object);
+ supports_password = empathy_sasl_channel_supports_mechanism (data->channel,
+ "X-TELEPATHY-PASSWORD");
+ if (password != NULL && supports_password)
+ {
+ DEBUG ("Goa daemon has credentials for %s, get the password",
+ tp_proxy_get_object_path (data->account));
- goa_oauth2_based_call_get_access_token (oauth2, NULL,
- got_oauth2_access_token_cb, data);
+ /* arg_id is currently unused */
+ goa_password_based_call_get_password (password, "", NULL,
+ got_password_passwd_cb, data);
+
+ g_object_unref (password);
+ return;
+ }
- g_object_unref (oauth2);
+ DEBUG ("GoaObject does not implement oauth2 or password");
+ fail_auth (data);
}
static void
@@ -358,5 +404,6 @@ empathy_goa_auth_handler_supports (EmpathyGoaAuthHandler *self,
mech = empathy_sasl_channel_select_mechanism (channel);
return mech == EMPATHY_SASL_MECHANISM_FACEBOOK ||
mech == EMPATHY_SASL_MECHANISM_WLM ||
- mech == EMPATHY_SASL_MECHANISM_GOOGLE;
+ mech == EMPATHY_SASL_MECHANISM_GOOGLE ||
+ mech == EMPATHY_SASL_MECHANISM_PASSWORD;
}