aboutsummaryrefslogtreecommitdiff
path: root/python/Flask-Security/token-loader.patch
diff options
context:
space:
mode:
authorNikos Giotis <nikos.giotis@gmail.com>2017-03-05 11:21:37 +0700
committerWilly Sudiarto Raharjo <willysr@slackbuilds.org>2017-03-05 11:21:37 +0700
commitec4749187637b5a6fbca212aaa0e7e59898f9bbd (patch)
tree93abef6990b750437322fb3e913c8be2d9d1e309 /python/Flask-Security/token-loader.patch
parent0ec91175bde005e251340631f4be25f795e46333 (diff)
python/Flask-Security: Added (Simple security for Flask apps).
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
Diffstat (limited to 'python/Flask-Security/token-loader.patch')
-rw-r--r--python/Flask-Security/token-loader.patch96
1 files changed, 96 insertions, 0 deletions
diff --git a/python/Flask-Security/token-loader.patch b/python/Flask-Security/token-loader.patch
new file mode 100644
index 0000000000000..4bf5733c74093
--- /dev/null
+++ b/python/Flask-Security/token-loader.patch
@@ -0,0 +1,96 @@
+From 01a0d62b7e5246867d456de5515a1fe09eb0f2ed Mon Sep 17 00:00:00 2001
+From: Alan Hamlett <alan.hamlett@gmail.com>
+Date: Thu, 27 Oct 2016 15:04:07 +0200
+Subject: [PATCH 1/2] replace token loader with request loader to fix #81
+
+---
+ flask_security/core.py | 12 ++++++++++--
+ flask_security/decorators.py | 10 +---------
+ tests/test_common.py | 2 +-
+ 3 files changed, 12 insertions(+), 12 deletions(-)
+
+diff --git a/flask_security/core.py b/flask_security/core.py
+index 3256668..3bcef52 100644
+--- a/flask_security/core.py
++++ b/flask_security/core.py
+@@ -191,7 +191,15 @@ def _user_loader(user_id):
+ return _security.datastore.find_user(id=user_id)
+
+
+-def _token_loader(token):
++def _request_loader(request):
++ header_key = _security.token_authentication_header
++ args_key = _security.token_authentication_key
++ header_token = request.headers.get(header_key, None)
++ token = request.args.get(args_key, header_token)
++ if request.get_json(silent=True):
++ if not isinstance(request.json, list):
++ token = request.json.get(args_key, token)
++
+ try:
+ data = _security.remember_token_serializer.loads(token, max_age=_security.token_max_age)
+ user = _security.datastore.find_user(id=data[0])
+@@ -223,7 +231,7 @@ def _get_login_manager(app, anonymous_user):
+ lm.anonymous_user = anonymous_user or AnonymousUser
+ lm.login_view = '%s.login' % cv('BLUEPRINT_NAME', app=app)
+ lm.user_loader(_user_loader)
+- lm.token_loader(_token_loader)
++ lm.request_loader(_request_loader)
+
+ if cv('FLASH_MESSAGES', app=app):
+ lm.login_message, lm.login_message_category = cv('MSG_LOGIN', app=app)
+diff --git a/flask_security/decorators.py b/flask_security/decorators.py
+index 89e62e8..81fa2f0 100644
+--- a/flask_security/decorators.py
++++ b/flask_security/decorators.py
+@@ -58,15 +58,7 @@ def _get_unauthorized_view():
+
+
+ def _check_token():
+- header_key = _security.token_authentication_header
+- args_key = _security.token_authentication_key
+- header_token = request.headers.get(header_key, None)
+- token = request.args.get(args_key, header_token)
+- if request.get_json(silent=True):
+- if not isinstance(request.json, list):
+- token = request.json.get(args_key, token)
+-
+- user = _security.login_manager.token_callback(token)
++ user = _security.login_manager.request_callback(request)
+
+ if user and user.is_authenticated:
+ app = current_app._get_current_object()
+diff --git a/tests/test_common.py b/tests/test_common.py
+index e884ab5..531090f 100644
+--- a/tests/test_common.py
++++ b/tests/test_common.py
+@@ -271,7 +271,7 @@ def test_remember_token(client):
+ assert b'profile' in response.data
+
+
+-def test_token_loader_does_not_fail_with_invalid_token(client):
++def test_request_loader_does_not_fail_with_invalid_token(client):
+ c = Cookie(version=0, name='remember_token', value='None', port=None,
+ port_specified=False, domain='www.example.com',
+ domain_specified=False, domain_initial_dot=False, path='/',
+
+From 6d56450a2b88c7196eeeba503b8e4ae3cdc857aa Mon Sep 17 00:00:00 2001
+From: Alan Hamlett <alan.hamlett@gmail.com>
+Date: Fri, 28 Oct 2016 00:45:51 +0200
+Subject: [PATCH 2/2] remove max version requirement from Flask-Login
+
+---
+ requirements.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/requirements.txt b/requirements.txt
+index c2df730..bd79ce4 100644
+--- a/requirements.txt
++++ b/requirements.txt
+@@ -1,5 +1,5 @@
+ Flask>=0.9
+-Flask-Login>=0.3.0,<0.4
++Flask-Login>=0.3.0
+ Flask-Mail>=0.7.3
+ Flask-Principal>=0.3.3
+ Flask-WTF>=0.8