【问题标题】:Logout fails in Turbogears 2.2.2在 Turbogears 2.2.2 中注销失败
【发布时间】:2015-02-08 11:58:37
【问题描述】:

我有使用 TG 2.2.2 编写的应用程序,具有默认身份验证。最近几天,我在登录和退出时遇到问题。在 safari 中,创建了两个 authtkt cookie,一个为“beta.domain.com”,另一个为“.beta.domain.com”。调用 /logout_handler 后,仅删除域“beta.domain.com”的 cookie,但保留野域的 cookie。所以重新加载页面后,用户仍然登录。问题出现在本地主机以及生产环境中。

有趣的是,相同lib版本的其他应用程序正常工作,以及在其他浏览器中,没有使用virtualenv。

我真的不知道问题出在哪里,所以我会在请求时包含任何配置文件。一开始就包含了 app_config。

app_cfg.py

# -*- coding: utf-8 -*-
from tg.configuration import AppConfig

import cafeteria
from cafeteria import model
from cafeteria.lib import app_globals, helpers

base_config = AppConfig()
base_config.renderers = []
base_config.prefer_toscawidgets2 = True

base_config.package = cafeteria

base_config.renderers.append('json')

base_config.renderers.append('mako')
base_config.default_renderer = 'mako'

base_config.use_sqlalchemy = True
base_config.model = cafeteria.model
base_config.DBSession = cafeteria.model.DBSession
# Configure the authentication backend

# YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP
base_config.sa_auth.cookie_secret = "SOMESECRET"

base_config.auth_backend = 'sqlalchemy'

from tg.configuration.auth import TGAuthMetadata

# This tells to TurboGears how to retrieve the data for your user
class ApplicationAuthMetadata(TGAuthMetadata):
    def __init__(self, sa_auth):
        self.sa_auth = sa_auth
    def get_user(self, identity, userid):
        return self.sa_auth.dbsession.query(self.sa_auth.user_class).filter_by(user_name = userid).first()
    def get_groups(self, identity, userid):
        return (identity['user'].group.name,) if identity['user'].group_id else []
    def get_permissions(self, identity, userid):
        return [p.name for p in identity['user'].group.permissions] if identity['user'].group_id else []


base_config.sa_auth.dbsession = model.DBSession
base_config.sa_auth.user_class = model.User
# base_config.sa_auth.group_class = model.Group
# base_config.sa_auth.permission_class = model.Permission

base_config.sa_auth.translations.group_name = 'name'
base_config.sa_auth.translations.permission_name = 'name'

base_config.sa_auth.authmetadata = ApplicationAuthMetadata(base_config.sa_auth)

# base_config.sa_auth.authenticators = [('myauth', SomeAuthenticator()]
# base_config.sa_auth.mdproviders = [('myprovider', SomeMDProvider()]

base_config.sa_auth.form_plugin = None
base_config.sa_auth.charset = 'utf-8'
base_config.sa_auth.post_login_url = '/post_login'
base_config.sa_auth.post_logout_url = '/post_logout'

【问题讨论】:

  • 很抱歉我之前没有看到这个。如果您仍然需要一些帮助,我很乐意尝试一下。您能否同时包含注销请求及其响应的 HTTP 标头和正文?
  • 另外,如果您可以在运行它的(非虚拟)环境中包含pip freeze 的输出,将会很有帮助。

标签: python pylons turbogears2


【解决方案1】:
  1. 删除您域的所有 cookie。当您更改域时,旧 cookie 仍然存在,可能会导致此问题。
  2. 为什么同时使用beta.domain.com.beta.domain.com?如果您不需要在子域中使用此 cookie,请删除第二个,否则只需使用 .beta.domain.com

如果这没有帮助,请附上请求和响应标头。

【讨论】:

    猜你喜欢
    • 2020-05-08
    • 2013-08-16
    • 2013-12-07
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    相关资源
    最近更新 更多