diff --git a/setup.py b/setup.py index 1aea5568a..e11f4ab0e 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/src/octoprint/server/util/tornado.py b/src/octoprint/server/util/tornado.py index 1ac58ada1..a7b15be97 100644 --- a/src/octoprint/server/util/tornado.py +++ b/src/octoprint/server/util/tornado.py @@ -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