*/
#include "config.h"
+#include "empathy-sasl-mechanisms.h"
#include <libsoup/soup.h>
-#include <string.h>
#define DEBUG_FLAG EMPATHY_DEBUG_SASL
#include "empathy-debug.h"
#include "empathy-utils.h"
-#include "empathy-sasl-mechanisms.h"
#define MECH_FACEBOOK "X-FACEBOOK-PLATFORM"
#define MECH_WLM "X-MESSENGER-OAUTH2"
+#define MECH_GOOGLE "X-OAUTH2"
+#define MECH_PASSWORD "X-TELEPATHY-PASSWORD"
typedef struct
{
static SupportedMech supported_mechanisms[] = {
{ EMPATHY_SASL_MECHANISM_FACEBOOK, MECH_FACEBOOK },
{ EMPATHY_SASL_MECHANISM_WLM, MECH_WLM },
+ { EMPATHY_SASL_MECHANISM_GOOGLE, MECH_GOOGLE },
+
+ /* Must be the last one, otherwise empathy_sasl_channel_select_mechanism()
+ * will prefer password over web auth for servers supporting both. */
+ { EMPATHY_SASL_MECHANISM_PASSWORD, MECH_PASSWORD }
};
static void
tp_proxy_dbus_error_to_gerror (channel, dbus_error,
tp_asv_get_string (details, "debug-message"), &error);
+ DEBUG ("SASL failed: %s", error->message);
+
g_simple_async_result_take_error (result, error);
+ g_simple_async_result_complete (result);
}
break;
case TP_SASL_STATUS_SUCCEEDED:
+ DEBUG ("SASL succeeded");
+
g_simple_async_result_complete (result);
break;
g_object_unref (result);
}
+void
+empathy_sasl_auth_google_async (TpChannel *channel,
+ const gchar *username,
+ const gchar *access_token,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ GArray *credential;
+
+ result = empathy_sasl_auth_common_async (channel, callback, user_data);
+
+ g_return_if_fail (result != NULL);
+ g_return_if_fail (empathy_sasl_channel_supports_mechanism (channel,
+ MECH_GOOGLE));
+ g_return_if_fail (!tp_str_empty (username));
+ g_return_if_fail (!tp_str_empty (access_token));
+
+ DEBUG ("Start %s mechanism", MECH_GOOGLE);
+
+ credential = g_array_sized_new (FALSE, FALSE, sizeof (gchar),
+ strlen (access_token) + strlen (username) + 2);
+
+ g_array_append_val (credential, "\0");
+ g_array_append_vals (credential, username, strlen (username));
+ g_array_append_val (credential, "\0");
+ g_array_append_vals (credential, access_token, strlen (access_token));
+
+ tp_cli_channel_interface_sasl_authentication_call_start_mechanism_with_data (
+ channel, -1, MECH_GOOGLE, credential,
+ generic_cb, g_object_ref (result), g_object_unref, NULL);
+
+ g_array_unref (credential);
+ g_object_unref (result);
+}
+
+void
+empathy_sasl_auth_password_async (TpChannel *channel,
+ const gchar *password,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ GArray *password_array;
+
+ result = empathy_sasl_auth_common_async (channel, callback, user_data);
+
+ g_return_if_fail (result != NULL);
+ g_return_if_fail (empathy_sasl_channel_supports_mechanism (channel,
+ MECH_PASSWORD));
+ g_return_if_fail (!tp_str_empty (password));
+
+ DEBUG ("Start %s mechanism", MECH_PASSWORD);
+
+ password_array = g_array_sized_new (FALSE, FALSE, sizeof (gchar),
+ strlen (password));
+ g_array_append_vals (password_array, password, strlen (password));
+
+ tp_cli_channel_interface_sasl_authentication_call_start_mechanism_with_data (
+ channel, -1, MECH_PASSWORD, password_array,
+ generic_cb, g_object_ref (result), g_object_unref, NULL);
+
+ g_array_unref (password_array);
+ g_object_unref (result);
+}
+
gboolean
empathy_sasl_auth_finish (TpChannel *channel,
GAsyncResult *result,
empathy_sasl_channel_supports_mechanism (TpChannel *channel,
const gchar *mechanism)
{
- GHashTable *props;
- const gchar * const *available_mechanisms;
+ GVariant *props;
+ GStrv available_mechanisms;
+ gboolean result;
- props = tp_channel_borrow_immutable_properties (channel);
- available_mechanisms = tp_asv_get_boxed (props,
+ props = tp_channel_dup_immutable_properties (channel);
+
+ g_variant_lookup (props,
TP_PROP_CHANNEL_INTERFACE_SASL_AUTHENTICATION_AVAILABLE_MECHANISMS,
- G_TYPE_STRV);
+ "^as", &available_mechanisms);
+
+ result = tp_strv_contains ((const gchar * const *) available_mechanisms,
+ mechanism);
- return tp_strv_contains (available_mechanisms, mechanism);
+ g_variant_unref (props);
+ g_strfreev (available_mechanisms);
+ return result;
}
EmpathySaslMechanism