2015-11-07 37 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,但它沒有幫助。 –