basic auth doesn't work in my case



dear libsoup experts,

following the documentation, i've added some primitive auth to the simple-
httpd.c example of libsoup 2.53.90

diff -u simple-httpd.c auth-httpd.c
--- simple-httpd.c      2016-03-08 12:15:30.682505044 +0100
+++ auth-httpd.c        2016-03-08 12:14:48.958441838 +0100
@@ -21,6 +21,13 @@
        return strcmp (*sa, *sb);
 }
 
+static gboolean soup_basic_auth_cb (SoupAuthDomain * domain, SoupMessage * 
msg,
+    const char *username, const char *password, gpointer user_data)
+{
+       g_print ("\n\nsoup_basic_auth_cb %s:%s\n\n", username, password);
+       return (strcmp (username, "bla") == 0) && (strcmp (password, "fasel") 
== 0);
+}
+
 static GString *
 get_directory_listing (const char *path)
 {
@@ -280,6 +287,10 @@
        soup_server_add_handler (server, NULL,
                                 server_callback, NULL, NULL);
 
+       SoupAuthDomain *auth_domain = soup_auth_domain_basic_new 
(SOUP_AUTH_DOMAIN_REALM, "realm", SOUP_AUTH_DOMAIN_ADD_PATH, "/", NULL);
+       soup_auth_domain_basic_set_auth_callback (auth_domain, 
soup_basic_auth_cb, NULL, NULL);
+       soup_server_add_auth_domain (server, auth_domain);
+
        uris = soup_server_get_uris (server);
        for (u = uris; u; u = u->next) {
                str = soup_uri_to_string (u->data, FALSE);

this works nicely, however when i add the same code to my application which is  
a glib / gstreamer application with a built-in libsoup server (restricted to 
version 2.42.1 due to crosscompiling environment), i always get 
401 unauthorized with the auth callback never being called.

the relevant lines from function in which in create the soup server are:

gboolean enable_hls_server(App *app, guint port)
{
...
                h->port = port;
                h->soupserver = soup_server_new (SOUP_SERVER_PORT, h->port, 
SOUP_SERVER_SERVER_HEADER, "dreamhttplive", NULL);
                soup_server_add_handler (h->soupserver, NULL, soup_server_callback, app, 
NULL);
//              SoupAuthDomain *auth_domain = soup_auth_domain_basic_new 
(SOUP_AUTH_DOMAIN_REALM, HLS_SOUP_REALM, SOUP_AUTH_DOMAIN_BASIC_AUTH_CALLBACK, 
soup_basic_auth_cb, SOUP_AUTH_DOMAIN_BASIC_AUTH_DATA, (gpointer) &app, 
SOUP_AUTH_DOMAIN_ADD_PATH, "/", NULL);
                SoupAuthDomain *auth_domain = soup_auth_domain_basic_new 
(SOUP_AUTH_DOMAIN_REALM, "realm", SOUP_AUTH_DOMAIN_ADD_PATH, "/", NULL);
                soup_auth_domain_basic_set_auth_callback (auth_domain, 
soup_basic_auth_cb, NULL, NULL);
                soup_server_add_auth_domain (h->soupserver, auth_domain);
                g_object_unref (auth_domain);
                soup_server_run_async (h->soupserver);
...
}

note the use of deprecated soup-server_run_async api because i have to use the 
older version here. this is probably why the authentication doesn't work.
do you have any suggestion how to get basic auth working with 2.42.1 ?

regards,
andreas / fraxinas



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]