nsIAuthPrompt2 编辑

netwerk/base/public/nsIAuthPrompt2.idlScriptable An interface allowing to prompt for a username and password. 1.0 66 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.

This interface is implemented by @mozilla.org/login-manager/prompter;1. To create an instance, use:

var authPrompt2 = Components.classes["@mozilla.org/login-manager/prompter;1"]
                  .createInstance(Components.interfaces.nsIAuthPrompt2);

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

ConstantValueDescription
LEVEL_NONE0The password will be sent unencrypted. No security provided.
LEVEL_PW_ENCRYPTED1Password will be sent encrypted, but the connection is otherwise insecure.
LEVEL_SECURE2The 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:91 次

字数:6831

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文