英文:
Flask-login not logging with Flask 2.3.2
问题
Tested both on Python 3.8 and 3.11.2
我在Python 3.8和3.11.2上都进行了测试。
I updated today from Flask 2.2.3 to 2.3.2 and login isn't working anymore.
我今天从Flask 2.2.3升级到2.3.2,但登录不再起作用。
I use Flask-login (0.6.2).
我使用Flask-login(0.6.2)。
When, after
当在以下操作后
login_user(user)
登录用户(user)
the app makes a redirect to the user homepage, here the current_user is anonymous.
应用程序重定向到用户主页时,current_user在此处是匿名的。
英文:
Tested both on Python 3.8 and 3.11.2
I updated today from Flask 2.2.3 to 2.3.2 and login isn't working anymore.
I use Flask-login (0.6.2).
When, after
login_user(user)
the app makes a redirect to the user homepage, here the current_user is anonymous.
答案1
得分: 1
I've found out that the cause is that since Flask 2.3.0 SESSION_COOKIE_DOMAIN does not fall back to SERVER_NAME.
In previous Flask, if SESSION_COOKIE_DOMAIN was not set, then the cookie will be valid for all subdomains of SERVER_NAME.
Since in my application after authentication (in appdomain.com) the user is redirect to her homepage in her own subdomain (username.appdomain.com), then I had to set SESSION_COOKIE_DOMAIN so that the cookie would be valid for all subdomains of SERVER_NAME.
So I set this configuration:
SESSION_COOKIE_DOMAIN = ".appdomain.com"
and it's working.
英文:
I've found out that the cause is that since Flask 2.3.0 SESSION_COOKIE_DOMAIN does not fall back to SERVER_NAME.
In previous Flask, if SESSION_COOKIE_DOMAIN was not set, then the cookie will be valid for all subdomains of SERVER_NAME.
Since in my application after authentication (in appdomain.com) the user is redirect to her homepage in her own subdomain (username.appdomain.com), then I had to set SESSION_COOKIE_DOMAIN so that the cookie would be valid for all subdomains of SERVER_NAME.
So I set this configuration:
SESSION_COOKIE_DOMAIN = ".appdomain.com"
and it's working.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论