nsIAuthPrompt2

An interface allowing to prompt for a username and password.
1.0
28
Introduced
Gecko 1.9
Inherits from: nsISupports Last changed in Gecko 1.9 (Firefox 3)

This interface is usually acquired using getInterface on notification callbacks or similar. It can be used to prompt users for authentication information, either synchronously or asynchronously.

Method overview

nsICancelable asyncPromptAuth(in nsIChannel aChannel, in nsIAuthPromptCallback aCallback, in nsISupports aContext, in PRUint32 level, in nsIAuthInformation authInfo);
boolean promptAuth(in nsIChannel aChannel, in PRUint32 level, in nsIAuthInformation authInfo);

Constants

Constant Value Description
LEVEL_NONE 0 The password will be sent unencrypted. No security provided.
LEVEL_PW_ENCRYPTED 1 Password will be sent encrypted, but the connection is otherwise insecure.
LEVEL_SECURE 2 The connection, both for password and data, is secure.

Methods

asyncPromptAuth()

Asynchronously prompt the user for a username and password. This has largely the same semantics as nsIAuthPrompt.promptUsernameAndPassword(), but must return immediately after calling and return the entered data in a callback.

If the user closes the dialog using a cancel button or similar, the callback's nsIAuthPromptCallback.onAuthCancelled() method must be called. Calling nsICancelable.cancel() on the returned object should close the dialog and must call nsIAuthPromptCallback.onAuthCancelled() on the provided callback.

This implementation may:

  1. Coalesce identical prompts. This means prompts that are guaranteed to want the same authentication information from the user. A single prompt will be shown; then the callbacks for all the coalesced prompts will be notified with the resulting authentication information.
  2. Serialize prompts that are all in the same "context" (this might mean application-wide, for a given window, or something else depending on the user interface) so that the user is not deluged with prompts.

Note: This method may throw any exception when the prompt fails to queue, for example because of out-of-memory error. It must not throw when the prompt could already be potentially shown to the user. In that case information about the failure has to come through the callback. This way we prevent multiple dialogs shown to the user because consumer may fall back to synchronous prompt on synchronous failure of this method.

nsICancelable asyncPromptAuth(
  in nsIChannel aChannel,
  in nsIAuthPromptCallback aCallback,
  in nsISupports aContext,
  in PRUint32 level,
  in nsIAuthInformation authInfo
);
Parameters
aChannel
The channel that requires authentication.
aCallback
aContext
level
One of the level constants.
authInfo
Authentication information object. The implementation should fill in this object with the information entered by the user before returning.
Return value

 

promptAuth()

Requests a username and a password. Implementations will commonly show a dialog with a username and password field, depending on flags also a domain field.

Note: Exceptions thrown from this function will be treated like a return value of false.

boolean promptAuth(
  in nsIChannel aChannel,
  in PRUint32 level,
  in nsIAuthInformation authInfo
);
Parameters
aChannel
The channel that requires authentication.
level
One of the level constants.
authInfo
Authentication information object. The implementation should fill in this object with the information entered by the user before returning.
Return value

false, authentication should be cancelled, usually because the user did not provide username/password. true, authentication can proceed using the values in the authInfo object.

See also

Document Tags and Contributors

Contributors to this page: Sheppy, trevorh
Last updated by: Sheppy,