summaryrefslogtreecommitdiff
path: root/python/Flask-Security/token-loader.patch
blob: 4bf5733c74093f6a2fe701064420a65a4bd21f70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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