【问题标题】:Cherrypy Authenticate every request without cachingCherrypy 对每个请求进行身份验证而不进行缓存
【发布时间】:2016-02-08 13:56:59
【问题描述】:

我编写了一个cherrypy 服务器来促进文件下载,并使用cherrypy auth digest 对其进行身份验证。对此的配置是:

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>
   }
}

那把钥匙的作用是什么?

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

【问题讨论】:

    标签: python authentication cherrypy


    【解决方案1】:

    将密钥视为会话 ID。一旦用户访问您的网站,您就会生成它...

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

    然后您在用户的 cookie 中设置该 ID,然后比较两个键以确保您拥有相同的用户。这就是使用“tools.sessions.on”背后的概念:是的,在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?

    但这是一个简单的身份验证,您可以在其中强制注销...

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

    希望这会有所帮助!

    【讨论】:

    • 发出成功请求后,我搜索了浏览器的本地存储和 cookie,但找不到该密钥。服务器如何存储这个密钥?
    • 我已经更新了我的答案并添加了一个链接,其中包含有关摘要身份验证的更多详细信息,但我认为如果不查看“tools.sessions.on”,您将无法实现您想要的:True设置。
    • 谢谢安德鲁。我尝试将“tools.sessions.on”设置为 false,但没有帮助。
    • 我是说摘要身份验证对您需要使用cherrypy会话进行研究的情况无济于事...stackoverflow.com/questions/13318215/…
    猜你喜欢
    • 1970-01-01
    • 2017-09-12
    • 2012-06-13
    • 2013-11-22
    • 2020-08-16
    • 2013-04-17
    • 2023-03-31
    • 2012-08-21
    • 2014-12-20
    相关资源
    最近更新 更多