用户未登录 - 会话cookie太大了?

问题描述 投票:1回答:1

我在这里关注google app engine / python的身份验证教程:https://cloud.google.com/python/getting-started/authenticate-users

我确定我已经正确地遵循了所有内容,但是当我单击页面上的登录按钮时,系统会提示我使用google登录,但是当重定向回页面时,它会显示用户未登录。

我检查了本地服务器,它说:

UserWarning: The "session" cookie is too large: the value was 4755 bytes but the header required 26 extra bytes. The final size was 4781 bytes but the limit is 4093 bytes. Browsers may silently ignore cookies larger than this.

我不是100%肯定这是我的问题,但它是唯一突出我的东西。有人可以帮忙吗?

python google-app-engine flask
1个回答
0
投票

是的,验证身份验证所需的所有数据都在cookie中,并且您在其中存储了太多信息。

您可以在_request_user_info()钩子中减少为配置文件存储的内容:

def _request_user_info(credentials):
    # ...
    resp, content = http.request(
        'https://www.googleapis.com/plus/v1/people/me')

    # ...
    session['profile'] = json.loads(content.decode('utf-8'))

而不是存储整个字典,过滤json.loads()返回的字典,只保留应用程序真正需要的配置文件信息。那,或者将这些信息存储在其他地方,就像在memcached中一样(所以每次你需要它时都要检索它,而且它在memcached中仍然不可用)。

查看People resource documentation以查看session['profile']中存储的数据并选择您真正需要的数据。例如,教程只需要显示名称和图像URL:

profile = json.loads(content.decode('utf-8'))
session['profile'] = {'displayName': profile['displayName'], 'image': profile['image']}
© www.soinside.com 2019 - 2024. All rights reserved.