1 module webkit2.AuthenticationRequest; 2 3 private import glib.Str; 4 private import gobject.ObjectG; 5 private import gobject.Signals; 6 private import std.algorithm; 7 private import webkit2.Credential; 8 private import webkit2.SecurityOrigin; 9 private import webkit2.c.functions; 10 public import webkit2.c.types; 11 12 13 /** 14 * Whenever a client attempts to load a page protected by HTTP 15 * authentication, credentials will need to be provided to authorize access. 16 * To allow the client to decide how it wishes to handle authentication, 17 * WebKit will fire a #WebKitWebView::authenticate signal with a 18 * WebKitAuthenticationRequest object to provide client side 19 * authentication support. Credentials are exposed through the 20 * #WebKitCredential object. 21 * 22 * In case the client application does not wish 23 * to handle this signal WebKit will provide a default handler. To handle 24 * authentication asynchronously, simply increase the reference count of the 25 * WebKitAuthenticationRequest object. 26 */ 27 public class AuthenticationRequest : ObjectG 28 { 29 /** the main Gtk struct */ 30 protected WebKitAuthenticationRequest* webKitAuthenticationRequest; 31 32 /** Get the main Gtk struct */ 33 public WebKitAuthenticationRequest* getAuthenticationRequestStruct(bool transferOwnership = false) 34 { 35 if (transferOwnership) 36 ownedRef = false; 37 return webKitAuthenticationRequest; 38 } 39 40 /** the main Gtk struct as a void* */ 41 protected override void* getStruct() 42 { 43 return cast(void*)webKitAuthenticationRequest; 44 } 45 46 /** 47 * Sets our main struct and passes it to the parent class. 48 */ 49 public this (WebKitAuthenticationRequest* webKitAuthenticationRequest, bool ownedRef = false) 50 { 51 this.webKitAuthenticationRequest = webKitAuthenticationRequest; 52 super(cast(GObject*)webKitAuthenticationRequest, ownedRef); 53 } 54 55 56 /** */ 57 public static GType getType() 58 { 59 return webkit_authentication_request_get_type(); 60 } 61 62 /** 63 * Authenticate the #WebKitAuthenticationRequest using the #WebKitCredential 64 * supplied. To continue without credentials, pass %NULL as @credential. 65 * 66 * Params: 67 * credential = A #WebKitCredential, or %NULL 68 * 69 * Since: 2.2 70 */ 71 public void authenticate(Credential credential) 72 { 73 webkit_authentication_request_authenticate(webKitAuthenticationRequest, (credential is null) ? null : credential.getCredentialStruct()); 74 } 75 76 /** 77 * Determine whether the authentication method associated with this 78 * #WebKitAuthenticationRequest should allow the storage of credentials. 79 * This will return %FALSE if WebKit doesn't support credential storing, 80 * if private browsing is enabled, or if persistent credential storage has been 81 * disabled in #WebKitWebsiteDataManager, unless credentials saving has been 82 * explicitly enabled with webkit_authentication_request_set_can_save_credentials(). 83 * 84 * Returns: %TRUE if WebKit can store credentials or %FALSE otherwise. 85 * 86 * Since: 2.2 87 */ 88 public bool canSaveCredentials() 89 { 90 return webkit_authentication_request_can_save_credentials(webKitAuthenticationRequest) != 0; 91 } 92 93 /** 94 * Cancel the authentication challenge. This will also cancel the page loading and result in a 95 * #WebKitWebView::load-failed signal with a #WebKitNetworkError of type %WEBKIT_NETWORK_ERROR_CANCELLED being emitted. 96 * 97 * Since: 2.2 98 */ 99 public void cancel() 100 { 101 webkit_authentication_request_cancel(webKitAuthenticationRequest); 102 } 103 104 /** 105 * Get the host that this authentication challenge is applicable to. 106 * 107 * Returns: The host of @request. 108 * 109 * Since: 2.2 110 */ 111 public string getHost() 112 { 113 return Str.toString(webkit_authentication_request_get_host(webKitAuthenticationRequest)); 114 } 115 116 /** 117 * Get the port that this authentication challenge is applicable to. 118 * 119 * Returns: The port of @request. 120 * 121 * Since: 2.2 122 */ 123 public uint getPort() 124 { 125 return webkit_authentication_request_get_port(webKitAuthenticationRequest); 126 } 127 128 /** 129 * Get the #WebKitCredential of the proposed authentication challenge that was 130 * stored from a previous session. The client can use this directly for 131 * authentication or construct their own #WebKitCredential. 132 * 133 * Returns: A #WebKitCredential encapsulating credential details 134 * or %NULL if there is no stored credential. 135 * 136 * Since: 2.2 137 */ 138 public Credential getProposedCredential() 139 { 140 auto __p = webkit_authentication_request_get_proposed_credential(webKitAuthenticationRequest); 141 142 if(__p is null) 143 { 144 return null; 145 } 146 147 return ObjectG.getDObject!(Credential)(cast(WebKitCredential*) __p, true); 148 } 149 150 /** 151 * Get the realm that this authentication challenge is applicable to. 152 * 153 * Returns: The realm of @request. 154 * 155 * Since: 2.2 156 */ 157 public string getRealm() 158 { 159 return Str.toString(webkit_authentication_request_get_realm(webKitAuthenticationRequest)); 160 } 161 162 /** 163 * Get the authentication scheme of the authentication challenge. 164 * 165 * Returns: The #WebKitAuthenticationScheme of @request. 166 * 167 * Since: 2.2 168 */ 169 public WebKitAuthenticationScheme getScheme() 170 { 171 return webkit_authentication_request_get_scheme(webKitAuthenticationRequest); 172 } 173 174 /** 175 * Get the #WebKitSecurityOrigin that this authentication challenge is applicable to. 176 * 177 * Returns: a newly created #WebKitSecurityOrigin. 178 * 179 * Since: 2.30 180 */ 181 public SecurityOrigin getSecurityOrigin() 182 { 183 auto __p = webkit_authentication_request_get_security_origin(webKitAuthenticationRequest); 184 185 if(__p is null) 186 { 187 return null; 188 } 189 190 return ObjectG.getDObject!(SecurityOrigin)(cast(WebKitSecurityOrigin*) __p, true); 191 } 192 193 /** 194 * Determine whether the authentication challenge is associated with a proxy server rather than an "origin" server. 195 * 196 * Returns: %TRUE if authentication is for a proxy or %FALSE otherwise. 197 * 198 * Since: 2.2 199 */ 200 public bool isForProxy() 201 { 202 return webkit_authentication_request_is_for_proxy(webKitAuthenticationRequest) != 0; 203 } 204 205 /** 206 * Determine whether this this is a first attempt or a retry for this authentication challenge. 207 * 208 * Returns: %TRUE if authentication attempt is a retry or %FALSE otherwise. 209 * 210 * Since: 2.2 211 */ 212 public bool isRetry() 213 { 214 return webkit_authentication_request_is_retry(webKitAuthenticationRequest) != 0; 215 } 216 217 /** 218 * Set whether the authentication method associated with @request 219 * should allow the storage of credentials. 220 * This should be used by applications handling their own credentials 221 * storage to indicate that it should be supported even when internal 222 * credential storage is disabled or unsupported. 223 * Note that storing of credentials will not be allowed on ephemeral 224 * sessions in any case. 225 * 226 * Params: 227 * enabled = value to set 228 * 229 * Since: 2.30 230 */ 231 public void setCanSaveCredentials(bool enabled) 232 { 233 webkit_authentication_request_set_can_save_credentials(webKitAuthenticationRequest, enabled); 234 } 235 236 /** 237 * Set the #WebKitCredential of the proposed authentication challenge that was 238 * stored from a previous session. This should only be used by applications handling 239 * their own credential storage. (When using the default WebKit credential storage, 240 * webkit_authentication_request_get_proposed_credential() already contains previously-stored 241 * credentials.) 242 * Passing a %NULL @credential will clear the proposed credential. 243 * 244 * Params: 245 * credential = a #WebKitCredential, or %NULL 246 * 247 * Since: 2.30 248 */ 249 public void setProposedCredential(Credential credential) 250 { 251 webkit_authentication_request_set_proposed_credential(webKitAuthenticationRequest, (credential is null) ? null : credential.getCredentialStruct()); 252 } 253 254 /** 255 * This signal is emitted when the user authentication request succeeded. 256 * Applications handling their own credential storage should connect to 257 * this signal to save the credentials. 258 * 259 * Params: 260 * credential = the #WebKitCredential accepted 261 * 262 * Since: 2.30 263 */ 264 gulong addOnAuthenticated(void delegate(Credential, AuthenticationRequest) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 265 { 266 return Signals.connect(this, "authenticated", dlg, connectFlags ^ ConnectFlags.SWAPPED); 267 } 268 269 /** 270 * This signal is emitted when the user authentication request is 271 * cancelled. It allows the application to dismiss its authentication 272 * dialog in case of page load failure for example. 273 * 274 * Since: 2.2 275 */ 276 gulong addOnCancelled(void delegate(AuthenticationRequest) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 277 { 278 return Signals.connect(this, "cancelled", dlg, connectFlags ^ ConnectFlags.SWAPPED); 279 } 280 }