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); }
END_TEST START_TEST(test_unregistered_identity) { g_type_init (); g_debug("%s", G_STRFUNC); SignonIdentity *idty = signon_identity_new(); fail_unless (idty != NULL); fail_unless (SIGNON_IS_IDENTITY (idty), "Failed to initialize the Identity."); SignonIdentityInfo *info = create_standard_info(); main_loop = g_main_loop_new (NULL, FALSE); signon_identity_store_credentials_with_info (idty, info, store_credentials_identity_cb, NULL); g_main_loop_run (main_loop); /* * give the time for identity to became idle * */ sleep(SIGNOND_IDLE_TIMEOUT); SignonIdentity *idty2 = signon_identity_new(); /* * give time to handle unregistered signal * */ g_timeout_add_seconds (5, test_quit_main_loop_cb, main_loop); signon_identity_query_info (idty, identity_info_cb, &info); g_main_loop_run (main_loop); g_object_unref (idty); g_object_unref (idty2); }
static void uoa_set_account_password (TpAccount *tp_account, const gchar *password, gboolean remember, GSimpleAsyncResult *result) { AgAccountService *service; AgAuthData *auth_data; guint cred_id; UoaChangePasswordData *data; SignonIdentity *identity; DEBUG ("Store password for %s in signond", tp_account_get_path_suffix (tp_account)); service = uoa_password_common (tp_account, result, &auth_data); if (service == NULL) return; data = uoa_change_password_data_new (service, password, remember, result); cred_id = ag_auth_data_get_credentials_id (auth_data); if (cred_id == 0) { SignonIdentityInfo *info; const GHashTable *params; const gchar *username; const gchar *acl_all[] = { "*", NULL }; /* This is the first time we store password for this account. * First check if we have an 'username' param as this is more accurate * in the tp-idle case. */ params = tp_account_get_parameters (tp_account); username = tp_asv_get_string (params, "username"); if (username == NULL) username = tp_asv_get_string (params, "account"); identity = signon_identity_new (); info = signon_identity_info_new (); signon_identity_info_set_username (info, username); signon_identity_info_set_secret (info, password, remember); signon_identity_info_set_access_control_list (info, acl_all); /* Give identity and data ownership to the callback */ signon_identity_store_credentials_with_info (identity, info, uoa_initial_identity_store_cb, data); signon_identity_info_free (info); } else { /* There is already a password stored, query info to update it. * Give identity and data ownership to the callback */ identity = signon_identity_new_from_db (cred_id); signon_identity_query_info (identity, uoa_identity_query_info_cb, data); } g_object_unref (service); ag_auth_data_unref (auth_data); }