<TITLE>SoupAuthManager</TITLE>
SoupAuthManager
SOUP_TYPE_AUTH_MANAGER
+soup_auth_manager_use_auth
<SUBSECTION Standard>
SoupAuthManagerPrivate
SoupAuthManagerClass
</refsect2>
+<refsect2 id="behavior">
+<title>Differences in feature behavior</title>
+
+<para>
+If you are using NTLM authentication, the new <type>SoupSession</type>
+behaves slightly differently from the old session types.
+</para>
+
+<para>
+First, the deprecated <link
+linkend="SOUP-SESSION-USE-NTLM:CAPS"><literal>SOUP_SESSION_USE_NTLM</literal></link>
+property is no longer supported. If you want to add support for NTLM
+to a session, call <link
+linkend="soup-session-add-feature-by-type"><function>soup_session_add_feature_by_type()</function></link>,
+passing <link
+linkend="SOUP-TYPE-AUTH-NTLM:CAPS"><literal>SOUP_TYPE_AUTH_NTLM</literal></link>.
+</para>
+
+<para>
+Second, with the old session types, enabling NTLM would cause all
+(otherwise-unauthenticated) requests to be sent with an NTLM request
+in the <literal>Authorization</literal> header. That is, libsoup would
+assume that all servers supported NTLM, and would attempt to begin
+negotiating NTLM authentication before the server ever returned a 401
+response. With the plain <type>SoupSession</type>, this no longer
+happens. If you want the old behavior, you need to call <link
+linkend="soup-auth-manager-use-auth"><function>soup_auth_manager_use_auth()</function></link>
+for each host to "preload" the NTLM authentication:
+</para>
+
+<informalexample><programlisting>
+ SoupAuthManager *auth_manager;
+ SoupAuth *auth;
+ SoupURI *uri;
+
+ auth_manager = SOUP_AUTH_MANAGER (soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER));
+ auth = g_object_new (SOUP_TYPE_AUTH_NTLM, NULL);
+ uri = soup_uri_new ("http://ntlm-using-host.example.com/");
+ soup_auth_manager_use_auth (auth_manager, uri, auth);
+ g_object_unref (auth);
+ soup_uri_free (auth);
+</programlisting></informalexample>
+
+</refsect2>
+
<refsect2 id="apis">
<title>Differences in SoupMessage-sending APIs</title>
soup_auth_is_for_proxy
soup_auth_is_ready
soup_auth_manager_get_type
+soup_auth_manager_use_auth
soup_auth_new
soup_auth_ntlm_get_type
soup_auth_save_password
g_ptr_array_add (priv->auth_types, auth_class);
g_ptr_array_sort (priv->auth_types, auth_type_compare_func);
- if (type == SOUP_TYPE_AUTH_NTLM)
+ /* Plain SoupSession does not get the backward-compat
+ * auto-NTLM behavior; SoupSession subclasses do.
+ */
+ if (type == SOUP_TYPE_AUTH_NTLM &&
+ G_TYPE_FROM_INSTANCE (priv->session) != SOUP_TYPE_SESSION)
priv->auto_ntlm = TRUE;
return TRUE;
0, 0, NULL, NULL, manager);
}
+/**
+ * soup_auth_manager_use_auth:
+ * @manager: a #SoupAuthManager
+ * @uri: the #SoupURI under which @auth is to be used
+ * @auth: the #SoupAuth to use
+ *
+ * Records that @auth is to be used under @uri, as though a
+ * WWW-Authenticate header had been received at that URI. This can be
+ * used to "preload" @manager's auth cache, to avoid an extra HTTP
+ * round trip in the case where you know ahead of time that a 401
+ * response will be returned.
+ *
+ * This is only useful for authentication types where the initial
+ * Authorization header does not depend on any additional information
+ * from the server. (Eg, Basic or NTLM, but not Digest.)
+ *
+ * Since: 2.42
+ */
+void
+soup_auth_manager_use_auth (SoupAuthManager *manager,
+ SoupURI *uri,
+ SoupAuth *auth)
+{
+ SoupAuthManagerPrivate *priv = manager->priv;
+
+ record_auth_for_uri (priv, uri, auth);
+}
+
static void
soup_auth_manager_session_feature_init (SoupSessionFeatureInterface *feature_interface,
gpointer interface_data)
GType soup_auth_manager_get_type (void);
+void soup_auth_manager_use_auth (SoupAuthManager *manager,
+ SoupURI *uri,
+ SoupAuth *auth);
+
G_END_DECLS
#endif /* SOUP_AUTH_MANAGER_H */
#include <string.h>
#include "soup-auth.h"
-#include "soup-headers.h"
+#include "soup.h"
+#include "soup-connection-auth.h"
#include "soup-marshal.h"
-#include "soup-uri.h"
/**
* SECTION:soup-auth
{
g_return_val_if_fail (SOUP_IS_AUTH (auth), NULL);
- return g_strdup_printf ("%s:%s",
- SOUP_AUTH_GET_CLASS (auth)->scheme_name,
- auth->realm);
+ if (SOUP_IS_CONNECTION_AUTH (auth))
+ return g_strdup (SOUP_AUTH_GET_CLASS (auth)->scheme_name);
+ else {
+ return g_strdup_printf ("%s:%s",
+ SOUP_AUTH_GET_CLASS (auth)->scheme_name,
+ auth->realm);
+ }
}
/**
gboolean bob_via_ntlm = use_ntlm && bob;
gboolean alice_via_basic = !use_ntlm && alice;
- session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
- if (use_ntlm)
- soup_session_add_feature_by_type (session, SOUP_TYPE_AUTH_NTLM);
+ session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
if (user) {
g_signal_connect (session, "authenticate",
if (use_ntlm && !use_builtin_ntlm)
g_setenv ("NTLMUSER", user, TRUE);
}
+ if (use_ntlm) {
+ SoupAuthManager *auth_manager;
+ SoupAuth *ntlm;
+
+ soup_session_add_feature_by_type (session, SOUP_TYPE_AUTH_NTLM);
+ auth_manager = SOUP_AUTH_MANAGER (soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER));
+ ntlm = g_object_new (SOUP_TYPE_AUTH_NTLM, NULL);
+ soup_auth_manager_use_auth (auth_manager, base_uri, ntlm);
+ g_object_unref (ntlm);
+ }
/* 1. Server doesn't request auth, so both get_ntlm_prompt and
* get_basic_prompt are both FALSE, and likewise do_basic. But
test_init (argc, argv, NULL);
- server = soup_test_server_new (FALSE);
+ server = soup_test_server_new (TRUE);
connections = g_hash_table_new (NULL, NULL);
soup_server_add_handler (server, NULL,
server_callback, connections, NULL);