跨两个应用程序的相同Flask登录会话 [英] Same Flask login session across two applications
问题描述
两个单独的Flask应用程序,在两个不同的子域上运行,但是登录会话在子域之间并不持久。
Two separate Flask applications, running on two different subdomains, however the login sessions are not persisting between the subdomains.
例如;登录到a.example.co.uk将导致用户登录。但是,访问b.example.co.uk-用户将无法登录。
For example; logging into a.example.co.uk will result in the user being logged in. However, visiting b.example.co.uk - the user will not be logged in.
运行Apache,Flask(带有Flask-Login),Ubuntu 18,Python 3。
Running Apache, Flask (with Flask-Login), Ubuntu 18, Python 3.
两个应用程序上的应用程序密码相同。尝试使用SERVER_NAME配置设置。
App secret is the same on both applications. Tried playing with SERVER_NAME configuration setting.
Cookies已正确设置为.example.co.uk
Cookies are correctly being set to .example.co.uk
Cookies配置为可在任何子域上使用。
Cookies are configured to be used on any subdomain.
SESSION_COOKIE_NAME="example",
SESSION_COOKIE_DOMAIN=".example.co.uk",
REMEMBER_COOKIE_DOMAIN=".example.co.uk",
推荐答案
可以解决该问题!
结果是我在wsgi文件中设置了Flask应用程序的秘密密钥,像这样;
Turns out I was setting the Flask application secret keys in the wsgi files, like so;
from App import app as application
application.secret_key = 'xxxxxxx'
这两个应用程序的wsgi文件中都有不同的秘密密钥!完全忘记了我在wsgi文件和主python文件中都设置了密钥。
And both the applications had different secret keys in their wsgi files! Completely forgot I was setting the secret keys in both the wsgi file and the main python file.
从wsgi文件中删除设置密钥解决了我的问题
Removing setting the secret keys from the wsgi files solved my problem
这篇关于跨两个应用程序的相同Flask登录会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!