2011-03-24 46 views
2

我無法讓金字塔的基本認證機制爲我工作。我做錯了嗎?金字塔認證問題(記住+ authenticated_userid)

要調試,我跑的代碼塊中的我的觀點之一:

print '$$$1', pyramid.security.remember(request, 12) 
print '$$$2', pyramid.security.unauthenticated_userid(request) 
print '$$$3', pyramid.security.authenticated_userid(request) 

這是我得到的輸出:

$$$ 1( '設置Cookie', 'auth_tkt =「45a66a6e860356b991cc8fc8acf9bf7f4d8b3d2212!userid_type:int」; Path = /'),('Set-Cookie','auth_tkt ='45a66a6e860356b991cc8fc8acf9bf7f4d8b3d2212!userid_type:int「; Path = /; Domain = 127.0.0.1:6543'), 'Set-Cookie','auth_tkt ='45a66a6e860356b991cc8fc8acf9bf7f4d8b3d2212!userid_type:int「; Path = /; Domain = .127.0.0.1:6543')]

$$$ 2無

$$$ 3無

我有工作的request.session我,所以我猜這個問題是不是與餅乾。

下面是我在__init__使用配置金字塔代碼:

authn_policy = AuthTktAuthenticationPolicy('secret', callback=lambda x:[]) 
engine = engine_from_config(settings, 'sqlalchemy.') 
initialize_sql(engine) 
my_session_factory = UnencryptedCookieSessionFactoryConfig('anothersecret') 
config = Configurator(settings=settings, session_factory=my_session_factory, 
         authentication_policy=authn_policy, 
     ) 

請幫幫忙!

回答

4

「記住」只是返回標題。您需要將這些標頭設置爲響應。另請參閱this section of Adding Authorization docs,特別是第21行下面的代碼示例22.

+0

請更新鏈接!這似乎是不正確的,也許是因爲官方網站重新設計? – Augiwan 2013-01-16 07:51:24

+0

更新了鏈接 – Efren 2018-01-22 00:00:15

1

您可能會在閱讀本教程時遇到同樣的錯誤,指出group_finder/only /返回附加組。這不是如此引用的情況:http://plope.com/pyramid_auth_design_api_postmortem

如果您使用回撥功能,則必須僅在用戶無效時返回無。該教程的示例將不返回任何不在枚舉用戶中的用戶(即使您是通過其他機制對用戶進行身份驗證)。在我自己的代碼中,我明確地返回一個空列表([]),用於尚未被記憶的列表/組中的用戶的情況。這樣我有三種訪問級別:公開的,已驗證的,基於組的權限。

除了教程的例子也有這一套食譜的條目: http://docs.pylonsproject.org/projects/pyramid_cookbook/dev/authentication.html