@@ -50,10 +50,10 @@ def verify_jwt_in_request(optional=False, fresh=False, refresh=False, locations=
5050 If ``True``, require a refresh JWT to be verified.
5151
5252 :param locations:
53- A list of locations to look for the JWT in this request, for example:
54- `` ['headers', 'cookies']``. Defaluts to ``None`` which indicates that JWTs
55- will be looked for in the locations defined by the ``JWT_TOKEN_LOCATION``
56- configuration option.
53+ A location or list of locations to look for the JWT in this request, for
54+ example ``'headers'`` or `` ['headers', 'cookies']``. Defaluts to ``None``
55+ which indicates that JWTs will be looked for in the locations defined by the
56+ ``JWT_TOKEN_LOCATION`` configuration option.
5757 """
5858 if request .method in config .exempt_methods :
5959 return
@@ -103,10 +103,10 @@ def jwt_required(optional=False, fresh=False, refresh=False, locations=None):
103103 requires an access JWT to access this endpoint. Defaults to ``False``.
104104
105105 :param locations:
106- A list of locations to look for the JWT in this request, for example:
107- `` ['headers', 'cookies']``. Defaluts to ``None`` which indicates that JWTs
108- will be looked for in the locations defined by the ``JWT_TOKEN_LOCATION``
109- configuration option.
106+ A location or list of locations to look for the JWT in this request, for
107+ example ``'headers'`` or `` ['headers', 'cookies']``. Defaluts to ``None``
108+ which indicates that JWTs will be looked for in the locations defined by the
109+ ``JWT_TOKEN_LOCATION`` configuration option.
110110 """
111111
112112 def wrapper (fn ):
@@ -227,26 +227,28 @@ def _decode_jwt_from_json(refresh):
227227
228228
229229def _decode_jwt_from_request (locations , fresh , refresh = False ):
230- # All the places we can get a JWT from in this request
231- get_encoded_token_functions = []
230+ # Figure out what locations to look for the JWT in this request
231+ if isinstance (locations , str ):
232+ locations = [locations ]
232233
233- # Get locations in the order specified by the decorator or JWT_TOKEN_LOCATION
234- # configuration.
235234 if not locations :
236235 locations = config .token_location
237236
238- # Add the functions in the order specified by locations.
237+ # Get the decode functions in the order specified by locations.
238+ get_encoded_token_functions = []
239239 for location in locations :
240240 if location == "cookies" :
241241 get_encoded_token_functions .append (
242242 lambda : _decode_jwt_from_cookies (refresh )
243243 )
244- if location == "query_string" :
244+ elif location == "query_string" :
245245 get_encoded_token_functions .append (_decode_jwt_from_query_string )
246- if location == "headers" :
246+ elif location == "headers" :
247247 get_encoded_token_functions .append (_decode_jwt_from_headers )
248- if location == "json" :
248+ elif location == "json" :
249249 get_encoded_token_functions .append (lambda : _decode_jwt_from_json (refresh ))
250+ else :
251+ raise RuntimeError (f"'{ location } ' is not a valid location" )
250252
251253 # Try to find the token from one of these locations. It only needs to exist
252254 # in one place to be valid (not every location).
0 commit comments