1 module soup.AuthManager;
2 
3 private import gobject.ObjectG;
4 private import gobject.Signals;
5 private import soup.Auth;
6 private import soup.Message;
7 private import soup.SessionFeatureIF;
8 private import soup.SessionFeatureT;
9 private import soup.URI;
10 private import soup.c.functions;
11 public  import soup.c.types;
12 private import std.algorithm;
13 
14 
15 /**
16  * #SoupAuthManager is the #SoupSessionFeature that handles HTTP
17  * authentication for a #SoupSession.
18  * 
19  * A #SoupAuthManager is added to the session by default, and normally
20  * you don't need to worry about it at all. However, if you want to
21  * disable HTTP authentication, you can remove the feature from the
22  * session with soup_session_remove_feature_by_type(), or disable it on
23  * individual requests with soup_message_disable_feature().
24  *
25  * Since: 2.42
26  */
27 public class AuthManager : ObjectG, SessionFeatureIF
28 {
29 	/** the main Gtk struct */
30 	protected SoupAuthManager* soupAuthManager;
31 
32 	/** Get the main Gtk struct */
33 	public SoupAuthManager* getAuthManagerStruct(bool transferOwnership = false)
34 	{
35 		if (transferOwnership)
36 			ownedRef = false;
37 		return soupAuthManager;
38 	}
39 
40 	/** the main Gtk struct as a void* */
41 	protected override void* getStruct()
42 	{
43 		return cast(void*)soupAuthManager;
44 	}
45 
46 	/**
47 	 * Sets our main struct and passes it to the parent class.
48 	 */
49 	public this (SoupAuthManager* soupAuthManager, bool ownedRef = false)
50 	{
51 		this.soupAuthManager = soupAuthManager;
52 		super(cast(GObject*)soupAuthManager, ownedRef);
53 	}
54 
55 	// add the SessionFeature capabilities
56 	mixin SessionFeatureT!(SoupAuthManager);
57 
58 
59 	/** */
60 	public static GType getType()
61 	{
62 		return soup_auth_manager_get_type();
63 	}
64 
65 	/**
66 	 * Clear all credentials cached by @manager
67 	 *
68 	 * Since: 2.58
69 	 */
70 	public void clearCachedCredentials()
71 	{
72 		soup_auth_manager_clear_cached_credentials(soupAuthManager);
73 	}
74 
75 	/**
76 	 * Records that @auth is to be used under @uri, as though a
77 	 * WWW-Authenticate header had been received at that URI. This can be
78 	 * used to "preload" @manager's auth cache, to avoid an extra HTTP
79 	 * round trip in the case where you know ahead of time that a 401
80 	 * response will be returned.
81 	 *
82 	 * This is only useful for authentication types where the initial
83 	 * Authorization header does not depend on any additional information
84 	 * from the server. (Eg, Basic or NTLM, but not Digest.)
85 	 *
86 	 * Params:
87 	 *     uri = the #SoupURI under which @auth is to be used
88 	 *     auth = the #SoupAuth to use
89 	 *
90 	 * Since: 2.42
91 	 */
92 	public void useAuth(URI uri, Auth auth)
93 	{
94 		soup_auth_manager_use_auth(soupAuthManager, (uri is null) ? null : uri.getURIStruct(), (auth is null) ? null : auth.getAuthStruct());
95 	}
96 
97 	/**
98 	 * Emitted when the manager requires the application to
99 	 * provide authentication credentials.
100 	 *
101 	 * #SoupSession connects to this signal and emits its own
102 	 * #SoupSession::authenticate signal when it is emitted, so
103 	 * you shouldn't need to use this signal directly.
104 	 *
105 	 * Params:
106 	 *     msg = the #SoupMessage being sent
107 	 *     auth = the #SoupAuth to authenticate
108 	 *     retrying = %TRUE if this is the second (or later) attempt
109 	 */
110 	gulong addOnAuthenticate(void delegate(Message, Auth, bool, AuthManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
111 	{
112 		return Signals.connect(this, "authenticate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
113 	}
114 }