Flask-login 在 Flask 2.3.2 中无法登录

huangapple go评论49阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月7日 01:48:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76190311.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定