cockpit_auth_local_async (CockpitAuth *self,
                          const gchar *user,
                          CockpitPipe *pipe,
                          GAsyncReadyCallback callback,
                          gpointer user_data)
{
  CockpitTransport *transport;
  CockpitSession *session;
  CockpitCreds *creds;
  gchar *csrf_token;

  g_return_if_fail (COCKPIT_IS_AUTH (self));
  g_return_if_fail (COCKPIT_IS_PIPE (pipe));
  g_return_if_fail (user != NULL);

  transport = cockpit_pipe_transport_new (pipe);

  csrf_token = cockpit_auth_nonce (self);
  creds = cockpit_creds_new ("cockpit",
                             COCKPIT_CRED_USER, user,
                             COCKPIT_CRED_RHOST, "localhost",
                             COCKPIT_CRED_CSRF_TOKEN, csrf_token,
                             NULL);

  session = cockpit_session_create (self, cockpit_pipe_get_name (pipe), creds, transport);

  session->cookie = g_strdup (LOCAL_SESSION);
  g_hash_table_insert (self->sessions, session->cookie, session);

  session->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
                                               cockpit_auth_local_async);

  g_free (csrf_token);
  g_object_unref (transport);
  cockpit_creds_unref (creds);
}
cockpit_auth_local_async (CockpitAuth *self,
                          const gchar *user,
                          CockpitPipe *pipe,
                          GAsyncReadyCallback callback,
                          gpointer user_data)
{
  CockpitTransport *transport;
  CockpitSession *session;
  CockpitCreds *creds;
  gchar *csrf_token;

  g_return_if_fail (COCKPIT_IS_AUTH (self));
  g_return_if_fail (COCKPIT_IS_PIPE (pipe));
  g_return_if_fail (user != NULL);

  transport = cockpit_pipe_transport_new (pipe);

  csrf_token = cockpit_auth_nonce (self);
  creds = cockpit_creds_new ("cockpit",
                             COCKPIT_CRED_USER, user,
                             COCKPIT_CRED_RHOST, "localhost",
                             COCKPIT_CRED_CSRF_TOKEN, csrf_token,
                             NULL);

  session = cockpit_session_create (self, cockpit_pipe_get_name (pipe), creds, transport);

  session->cookie = g_strdup (LOCAL_SESSION);
  g_hash_table_insert (self->sessions, session->cookie, session);

  session->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
                                               cockpit_auth_local_async);

  g_free (csrf_token);
  g_object_unref (transport);
  cockpit_creds_unref (creds);
}