cherrypy.lib.auth_Basic模块¶
HTTP基本身份验证工具。
该模块提供了一个cherrypy 3.x工具,它实现了HTTP基本访问身份验证的服务器端,如中所述。 RFC 2617 .
示例用法,使用内置的checkpassword_dict函数,该函数使用dict作为凭据存储:
userpassdict = {'bird' : 'bebop', 'ornette' : 'wayout'}
checkpassword = cherrypy.lib.auth_basic.checkpassword_dict(userpassdict)
basic_auth = {'tools.auth_basic.on': True,
'tools.auth_basic.realm': 'earth',
'tools.auth_basic.checkpassword': checkpassword,
'tools.auth_basic.accept_charset': 'UTF-8',
}
app_config = { '/' : basic_auth }
- cherrypy.lib.auth_basic.basic_auth(realm, checkpassword, debug=False, accept_charset='utf-8')[源代码]¶
一个cherrypy工具,它钩住before处理程序来执行HTTP基本访问身份验证,如中所述。 RFC 2617 和 RFC 7617 .
如果请求具有“基本”方案的“授权”头,则此工具将尝试对该头中提供的凭据进行身份验证。如果请求没有“authorization”头,或者如果请求没有“authorization”头,或者如果请求没有“basic”,或者如果验证失败,那么该工具将发送一个401响应,其中包含“www authenticate”基本头。
- 领域
包含身份验证领域的字符串。
- 检查密码
检查身份验证凭据的可调用文件。它的签名是checkpassword(领域、用户名、密码)。其中,用户名和密码是从请求的“授权”头中获取的值。如果验证成功,则checkpassword返回true,否则返回false。