2011-03-24 126 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