🐛 Fix auth on tornado endpoints again

Broke thanks to a breaking change hidden in the new flask-login version.
Just use semver, people, please!

Fixes #3600
This commit is contained in:
Gina Häußge committed 2020-06-12 10:16:51 +02:00
1 parent 31e98b8949
commit 55dafd511b
2 files changed
+15 -3

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ INSTALL_REQUIRES = [
"flask>=1.1.2,<2",
"Jinja2>=2.11.2,<3",
"Flask-Login>=0.5,<1",
"Flask-Login>=0.5,<0.6", # flask-login doesn't use semver & breaks stuff on minor version increases
"Flask-Babel>=1.0,<2",
"Flask-Assets>=2.0,<3",
"werkzeug>=1.0.1,<2",
+14 -2
View File
@@ -1270,6 +1270,8 @@ def access_validation_factory(app, validator, *args):
:param validator: the access validator to use inside the validation wrapper
:return: an access validator taking a request as parameter and performing the request validation
"""
# noinspection PyProtectedMember
def f(request):
"""
Creates a custom wsgi and Flask request context in order to be able to process user information
@@ -1281,8 +1283,18 @@ def access_validation_factory(app, validator, *args):
wsgi_environ = WsgiInputContainer.environ(request)
with app.request_context(wsgi_environ):
app.session_interface.open_session(app, flask.request)
app.login_manager.reload_user()
session = app.session_interface.open_session(app, flask.request)
user_id = session.get("user_id")
user = None
# Yes, using protected methods is ugly. But these used to be publicly available in former versions
# of flask-login, there are no replacements, and seeing them renamed & hidden in a minor version release
# without any mention in the changelog means the public API ain't strictly stable either, so we might
# as well make our life easier here and just use them...
if user_id is not None and app.login_manager._user_callback is not None:
user = app.login_manager._user_callback(user_id)
app.login_manager._update_request_context_with_user(user)
validator(flask.request, *args)
return f