diff --git a/telepathy-sasl-signon/empathy-sasl-mechanisms.c b/telepathy-sasl-signon/empathy-sasl-mechanisms.c index c47a702..78f6ed1 100644 --- a/telepathy-sasl-signon/empathy-sasl-mechanisms.c +++ b/telepathy-sasl-signon/empathy-sasl-mechanisms.c @@ -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; } diff --git a/telepathy-sasl-signon/empathy-sasl-mechanisms.h b/telepathy-sasl-signon/empathy-sasl-mechanisms.h index ef7ccd6..1298644 100644 --- a/telepathy-sasl-signon/empathy-sasl-mechanisms.h +++ b/telepathy-sasl-signon/empathy-sasl-mechanisms.h @@ -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 diff --git a/telepathy-sasl-signon/empathy-uoa-auth-handler.c b/telepathy-sasl-signon/empathy-uoa-auth-handler.c index c92ec89..7ce2928 100644 --- a/telepathy-sasl-signon/empathy-uoa-auth-handler.c +++ b/telepathy-sasl-signon/empathy-uoa-auth-handler.c @@ -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; }