Skip to content

Commit 8c5900c

Browse files
committed
Don't split header_name into access_header_name and refresh_header_name
This could use some more thought. Curreently, I don't think this would be a desired feature by anyone, and I want to avoid as much unnecessary options as possible. But, if this is something people want, I should be able to just revert this commit to get it back
1 parent e78de38 commit 8c5900c

File tree

4 files changed

+13
-46
lines changed

4 files changed

+13
-46
lines changed

flask_jwt_extended/config.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,13 @@ def jwt_in_cookies(self):
3434
def jwt_in_headers(self):
3535
return 'headers' in self.token_location
3636

37-
@staticmethod
38-
def _get_depreciated_header_name():
39-
# This used to be the same option for access and refresh header names.
40-
# This gives users a warning if they are still using the old behavior
41-
old_name = current_app.config.get('JWT_HEADER_NAME', None)
42-
if old_name:
43-
msg = (
44-
"JWT_HEADER_NAME is depreciated. Use JWT_ACCESS_HEADER_NAME "
45-
"or JWT_REFRESH_HEADER_NAME instead"
46-
)
47-
warn(msg, DeprecationWarning)
48-
return old_name
49-
5037
@property
51-
def access_header_name(self):
52-
name = self._get_depreciated_header_name() or \
53-
current_app.config['JWT_ACCESS_HEADER_NAME']
38+
def header_name(self):
39+
name = current_app.config['JWT_HEADER_NAME']
5440
if not name:
5541
raise RuntimeError("JWT_ACCESS_HEADER_NAME cannot be empty")
5642
return name
5743

58-
@property
59-
def refresh_header_name(self):
60-
name = self._get_depreciated_header_name() or \
61-
current_app.config['JWT_REFRESH_HEADER_NAME']
62-
if not name:
63-
raise RuntimeError("JWT_REFRESH_HEADER_NAME cannot be empty")
64-
return name
65-
6644
@property
6745
def header_type(self):
6846
return current_app.config['JWT_HEADER_TYPE']

flask_jwt_extended/decorators.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,9 @@ def wrapper(*args, **kwargs):
7575
return wrapper
7676

7777

78-
def _decode_jwt_from_headers(request_type):
79-
if request_type == 'access':
80-
header_name = config.access_header_name
81-
header_type = config.header_type
82-
else:
83-
header_name = config.refresh_header_name
84-
header_type = config.header_type
78+
def _decode_jwt_from_headers():
79+
header_name = config.header_name
80+
header_type = config.header_type
8581

8682
# Verify we have the auth header
8783
jwt_header = request.headers.get(header_name, None)
@@ -146,11 +142,11 @@ def _decode_jwt_from_request(request_type):
146142
decoded_token = _decode_jwt_from_cookies(request_type)
147143
except NoAuthorizationError:
148144
try:
149-
decoded_token = _decode_jwt_from_headers(request_type)
145+
decoded_token = _decode_jwt_from_headers()
150146
except NoAuthorizationError:
151147
raise NoAuthorizationError("Missing JWT in headers and cookies")
152148
elif config.jwt_in_headers:
153-
decoded_token = _decode_jwt_from_headers(request_type)
149+
decoded_token = _decode_jwt_from_headers()
154150
else:
155151
decoded_token = _decode_jwt_from_cookies(request_type)
156152

flask_jwt_extended/jwt_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ def _set_default_configuration_options(app):
110110
app.config.setdefault('JWT_TOKEN_LOCATION', ['headers'])
111111

112112
# Options for JWTs when the TOKEN_LOCATION is headers
113-
app.config.setdefault('JWT_ACCESS_HEADER_NAME', 'Authorization')
114-
app.config.setdefault('JWT_REFRESH_HEADER_NAME', 'Authorization')
113+
app.config.setdefault('JWT_HEADER_NAME', 'Authorization')
115114
app.config.setdefault('JWT_HEADER_TYPE', 'Bearer')
116115

117116
# Option for JWTs when the TOKEN_LOCATION is cookies

tests/test_config.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ def setUp(self):
1919
def test_default_configs(self):
2020
with self.app.test_request_context():
2121
self.assertEqual(config.token_location, ['headers'])
22-
self.assertEqual(config.access_header_name, 'Authorization')
23-
self.assertEqual(config.refresh_header_name, 'Authorization')
22+
self.assertEqual(config.header_name, 'Authorization')
2423
self.assertEqual(config.header_type, 'Bearer')
2524

2625
self.assertEqual(config.cookie_secure, False)
@@ -46,8 +45,7 @@ def test_default_configs(self):
4645

4746
def test_override_configs(self):
4847
self.app.config['JWT_TOKEN_LOCATION'] = 'cookies'
49-
self.app.config['JWT_ACCESS_HEADER_NAME'] = 'Auth'
50-
self.app.config['JWT_REFRESH_HEADER_NAME'] = 'Auth'
48+
self.app.config['JWT_HEADER_NAME'] = 'Auth'
5149
self.app.config['JWT_HEADER_TYPE'] = 'JWT'
5250

5351
self.app.config['JWT_COOKIE_SECURE'] = True
@@ -71,8 +69,7 @@ def test_override_configs(self):
7169

7270
with self.app.test_request_context():
7371
self.assertEqual(config.token_location, ['cookies'])
74-
self.assertEqual(config.access_header_name, 'Auth')
75-
self.assertEqual(config.refresh_header_name, 'Auth')
72+
self.assertEqual(config.header_name, 'Auth')
7673
self.assertEqual(config.header_type, 'JWT')
7774

7875
self.assertEqual(config.cookie_secure, True)
@@ -94,16 +91,13 @@ def test_override_configs(self):
9491
self.assertEqual(config.blacklist_checks, 'all')
9592

9693
self.app.config['JWT_TOKEN_LOCATION'] = 'banana'
97-
self.app.config['JWT_ACCESS_HEADER_NAME'] = ''
98-
self.app.config['JWT_REFRESH_HEADER_NAME'] = ''
94+
self.app.config['JWT_HEADER_NAME'] = ''
9995
self.app.config['JWT_ACCESS_TOKEN_EXPIRES'] = 'banana'
10096
self.app.config['JWT_REFRESH_TOKEN_EXPIRES'] = 'banana'
10197

10298
with self.app.test_request_context():
10399
with self.assertRaises(RuntimeError):
104-
config.access_header_name
105-
with self.assertRaises(RuntimeError):
106-
config.refresh_header_name
100+
config.header_name
107101
with self.assertRaises(RuntimeError):
108102
config.access_expires
109103
with self.assertRaises(RuntimeError):

0 commit comments

Comments
 (0)