void empathy_uoa_auth_handler_start (EmpathyUoaAuthHandler *self, TpChannel *channel, TpAccount *tp_account) { const GValue *id_value; AgAccountId id; AgAccount *account; GList *l = NULL; AgAccountService *service; AuthContext *ctx; g_return_if_fail (TP_IS_CHANNEL (channel)); g_return_if_fail (TP_IS_ACCOUNT (tp_account)); g_return_if_fail (empathy_uoa_auth_handler_supports (self, channel, tp_account)); DEBUG ("Start UOA auth for account: %s", tp_proxy_get_object_path (tp_account)); id_value = tp_account_get_storage_identifier (tp_account); id = g_value_get_uint (id_value); account = ag_manager_get_account (self->priv->manager, id); if (account != NULL) l = ag_account_list_services_by_type (account, TPAW_UOA_SERVICE_TYPE); if (l == NULL) { DEBUG ("Couldn't find IM service for AgAccountId %u", id); g_object_unref (account); tp_channel_close_async (channel, NULL, NULL); return; } /* Assume there is only one IM service */ service = ag_account_service_new (account, l->data); ag_service_list_free (l); g_object_unref (account); ctx = auth_context_new (channel, service); if (ctx->session == NULL) { /* This (usually?) means we never stored credentials for this account. * To ask user to type his password SSO needs a SignonIdentity bound to * our account. Let's store an empty password. */ DEBUG ("Couldn't create a signon session"); tpaw_keyring_set_account_password_async (tp_account, "", FALSE, set_account_password_cb, ctx); } else { /* All is fine! Query UOA for more info */ signon_identity_query_info (ctx->identity, identity_query_info_cb, ctx); } g_object_unref (service); }
static void manager_prepared_cb (GObject *source, GAsyncResult *result, gpointer user_data) { TpWeakRef *wr = user_data; EmpathyAppPluginWidget *self = tp_weak_ref_dup_object (wr); TpAccountManager *manager = (TpAccountManager *) source; GList *accounts; GError *error = NULL; if (self == NULL) { tp_weak_ref_destroy (wr); return; } if (!tp_proxy_prepare_finish (manager, result, &error)) { g_debug ("Error preparing Account Manager: %s", error->message); g_clear_error (&error); goto out; } accounts = tp_account_manager_dup_valid_accounts (manager); while (accounts != NULL) { TpAccount *account = accounts->data; const GValue *value; value = tp_account_get_storage_identifier (account); if (G_VALUE_HOLDS_UINT (value) && g_value_get_uint (value) == self->priv->account->id) { GtkWidget *alig; alig = gtk_alignment_new (0.5, 0, 0, 0); self->priv->user_info = tpaw_user_info_new (account); gtk_container_add (GTK_CONTAINER (alig), self->priv->user_info); gtk_widget_show (self->priv->user_info); gtk_box_pack_start (GTK_BOX (self), alig, TRUE, TRUE, 0); gtk_widget_show (alig); break; } accounts = g_list_delete_link (accounts, accounts); } g_list_free_full (accounts, g_object_unref); out: tp_weak_ref_destroy (wr); g_object_unref (self); }
static AgAccountService * uoa_password_common (TpAccount *tp_account, GSimpleAsyncResult *result, AgAuthData **ret_auth_data) { const GValue *storage_id; AgAccountId account_id; AgManager *manager = NULL; AgAccount *account = NULL; GList *l; AgAccountService *service = NULL; AgAuthData *auth_data = NULL; g_assert (ret_auth_data != NULL); *ret_auth_data = NULL; storage_id = tp_account_get_storage_identifier (tp_account); account_id = g_value_get_uint (storage_id); if (account_id == 0) { g_simple_async_result_set_error (result, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "StorageId is invalid, cannot get the AgAccount for this TpAccount"); g_simple_async_result_complete_in_idle (result); goto error; } manager = empathy_uoa_manager_dup (); account = ag_manager_get_account (manager, account_id); /* Assuming there is only one IM service */ l = ag_account_list_services_by_type (account, EMPATHY_UOA_SERVICE_TYPE); if (l == NULL) { g_simple_async_result_set_error (result, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "AgAccount has no IM service"); g_simple_async_result_complete_in_idle (result); goto error; } service = ag_account_service_new (account, l->data); ag_service_list_free (l); auth_data = ag_account_service_get_auth_data (service); if (auth_data == NULL) { g_simple_async_result_set_error (result, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "Service has no AgAuthData"); g_simple_async_result_complete_in_idle (result); goto error; } if (tp_strdiff (ag_auth_data_get_mechanism (auth_data), "password") || tp_strdiff (ag_auth_data_get_method (auth_data), "password")) { g_simple_async_result_set_error (result, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "Service does not use password authentication"); g_simple_async_result_complete_in_idle (result); goto error; } g_object_unref (manager); g_object_unref (account); *ret_auth_data = auth_data; return service; error: g_clear_object (&manager); g_clear_object (&account); g_clear_object (&service); tp_clear_pointer (&auth_data, ag_auth_data_unref); return NULL; }