Commit 08bc50c9 authored by John Brooks's avatar John Brooks

[telepathy-sasl-signon] Only attempt to use authentication methods which we have credentials for

This allows the use of, for example, password authentication on servers
that also support oauth2, depending on which credential is actually
configured.
parent 5d2507f4
......@@ -30,22 +30,6 @@
#define MECH_GOOGLE "X-OAUTH2"
#define MECH_PASSWORD "X-TELEPATHY-PASSWORD"
typedef struct
{
EmpathySaslMechanism id;
const gchar *name;
} SupportedMech;
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
generic_cb (TpChannel *proxy,
const GError *error,
......@@ -360,16 +344,26 @@ empathy_sasl_channel_supports_mechanism (TpChannel *channel,
}
EmpathySaslMechanism
empathy_sasl_channel_select_mechanism (TpChannel *channel)
empathy_sasl_channel_select_mechanism (TpChannel *channel,
const gchar *credential_type)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (supported_mechanisms); i++)
{
if (empathy_sasl_channel_supports_mechanism (channel,
supported_mechanisms[i].name))
return supported_mechanisms[i].id;
}
if (g_strcmp0 (credential_type, "password") == 0) {
if (empathy_sasl_channel_supports_mechanism (channel,
MECH_PASSWORD))
return EMPATHY_SASL_MECHANISM_PASSWORD;
} else if (g_strcmp0 (credential_type, "oauth2") == 0) {
if (empathy_sasl_channel_supports_mechanism (channel,
MECH_FACEBOOK))
return EMPATHY_SASL_MECHANISM_FACEBOOK;
else if (empathy_sasl_channel_supports_mechanism (channel,
MECH_WLM))
return EMPATHY_SASL_MECHANISM_WLM;
else if (empathy_sasl_channel_supports_mechanism (channel,
MECH_GOOGLE))
return EMPATHY_SASL_MECHANISM_GOOGLE;
}
return EMPATHY_SASL_MECHANISM_UNSUPPORTED;
}
......@@ -63,7 +63,8 @@ gboolean empathy_sasl_auth_finish (TpChannel *channel,
gboolean empathy_sasl_channel_supports_mechanism (TpChannel *channel,
const gchar *mechanism);
EmpathySaslMechanism empathy_sasl_channel_select_mechanism (TpChannel *channel);
EmpathySaslMechanism empathy_sasl_channel_select_mechanism (TpChannel *channel,
const gchar *credential_type);
G_END_DECLS
......
......@@ -213,6 +213,7 @@ session_process_cb (SignonAuthSession *session,
AuthContext *ctx = user_data;
const gchar *access_token;
const gchar *client_id;
const gchar *auth_method;
if (error != NULL)
{
......@@ -224,8 +225,9 @@ session_process_cb (SignonAuthSession *session,
access_token = tp_asv_get_string (session_data, "AccessToken");
client_id = tp_asv_get_string (ag_auth_data_get_parameters (ctx->auth_data),
"ClientId");
auth_method = signon_auth_session_get_method (session);
switch (empathy_sasl_channel_select_mechanism (ctx->channel))
switch (empathy_sasl_channel_select_mechanism (ctx->channel, auth_method))
{
case EMPATHY_SASL_MECHANISM_FACEBOOK:
empathy_sasl_auth_facebook_async (ctx->channel,
......@@ -393,9 +395,5 @@ empathy_uoa_auth_handler_supports (EmpathyUoaAuthHandler *self,
if (tp_strdiff (provider, EMPATHY_UOA_PROVIDER))
return FALSE;
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_PASSWORD;
return TRUE;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment