2015-11-07 54 views
0

我编写了一个cherrypy服务器以方便文件下载,并使用cherrypy auth摘要进行验证。此配置为:Cherrypy验证没有缓存的每个请求

conf = { 
    '/getXML': { 
     'tools.auth_digest.on': True, 
     'tools.auth_digest.realm': None, 
     'tools.auth_digest.get_ha1': auth_digest.get_ha1_dict_plain(USERS), 
     'tools.auth_digest.key': <some_key> 
    } 
} 

该密钥的作用是什么?

另外,成功验证后,当我再次打开服务器时,它会记住登录并且不会再次提示输入凭据。如何在不记住登录的情况下为每个请求申请凭据?

回答

0

将密钥视为会话ID。一旦用户来到你的网站,你产生的呢?

cherrypy.session['_csrf_token'] = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(16)) 

然后设置在用户的cookie那个ID和你比较两个键,以确保你有相同的用户。这就是使用'tools.sessions.on'的理念:True,设置为cherrypy。这使您可以在无状态环境(如http)中从一个页面到另一个页面了解用户。

https://cherrypy.readthedocs.org/en/3.3.0/refman/lib/auth_digest.html#cherrypy.lib.auth_digest.HttpDigestAuthorization.validate_nonce

** 
validate_nonce(s, key) 

    Validate the nonce. Returns True if nonce was generated by synthesize_nonce() and the timestamp is not spoofed, else returns False. 

    s 
     A string related to the resource, such as the hostname of the server. 
    key 
     A secret string known only to the server. 

    Both s and key must be the same values which were used to synthesize the nonce we are trying to validate. 
** 

看起来像强迫与权威性摘要注销是不可能的......

https://groups.google.com/d/msg/cherrypy-users/M-GUFH2mU_M/45zHnA5Y6XMJ

这里的摘要式身份验证的详细信息...

What is digest authentication?

但是,这是一个简单的authenication在那里你可以强制退出...

How to logout from a simple web appl. in CherryPy, Python

希望这有助于!

+0

做出成功的请求后,我搜索了浏览器的本地存储和cookie,但无法找到该密钥。服务器如何存储这个密钥? –

+0

我已经更新了我的答案,并添加了一个链接,其中包含关于摘要式身份验证的更多详细信息,但我不认为您会在不查看'tools.sessions.on'的情况下获得所需内容:真实设置。 –

+0

谢谢安德鲁。我尝试将'tools.sessions.on'设置为false,但它没有帮助。 –