Skip to content

Commit 98fb59e

Browse files
author
Landon Gilbert-Bland
committed
Minor documentation updates
1 parent e719536 commit 98fb59e

File tree

5 files changed

+56
-49
lines changed

5 files changed

+56
-49
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Flask-JWT-Extended
22

33
### Features
4-
Flask-JWT-Extended not only adds support for using JSON Web Tokens (JWT) to Flask for protecting views,
4+
Flask-JWT-Extended not only adds support for using JSON Web Tokens (JWT) to Flask for protecting routes,
55
but also many helpful (and **optional**) features built in to make working with JSON Web Tokens
66
easier. These include:
77

88
* Adding custom claims to JSON Web Tokens
9-
* Custom claims validation on received tokens
109
* Automatic user loading (`current_user`).
10+
* Custom claims validation on received tokens
1111
* [Refresh tokens](https://auth0.com/blog/refresh-tokens-what-are-they-and-when-to-use-them/)
1212
* First class support for fresh tokens for making sensitive changes.
1313
* Token revoking/blocklisting

docs/v4_upgrade_guide.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
This release includes a lot of breaking changes that have been a long time coming,
44
and will require some manual intervention to upgrade your application. Breaking
55
changes are never fun, but I really believe they are for the best. As a result
6-
of all these breaking changes, this extension should be simpiler to use,
7-
provide more flexibility, and allow for easier additions to the API without
8-
introducing further breaking changes in the future. Here are all the breaking
9-
changes that might affect your flask application when upgrading to 4.0.0.
10-
6+
of all these changes, this extension should be simpler to use, provide more
7+
flexibility, and allow for easier additions to the API without introducing
8+
further breaking changes. Here is everything you will need to be aware of when
9+
upgrading to 4.0.0.
1110

1211
Encoded JWT Changes (IMPORTANT)
1312
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -125,3 +124,11 @@ API Changes
125124
will now always be put in the JWT regardless of if it is an access or refresh
126125
tokens. If you don't want additional claims in your refresh tokens, do not
127126
include any additional claims when creating the refresh token.
127+
128+
New Stuff
129+
~~~~~~~~~
130+
- Add ``locations`` argument to ``@jwt_required()`` and ``verify_jwt_in_request``.
131+
This will allow you to override the ``JWT_LOCATIONS`` option on a per route basis.
132+
- Revamped and cleaned up documentation. It should be clearer how to work with this
133+
extension both on the backend and frontend now.
134+
- Lots of code cleanup behind the scenes.

flask_jwt_extended/jwt_manager.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def additional_claims_loader(self, callback):
207207
"""
208208
This decorator sets the callback function used to add additional claims
209209
when creating a JWT. The claims returned by this function will be merged
210-
with any claims passed in via the `additional_claims` argument to
210+
with any claims passed in via the ``additional_claims`` argument to
211211
:func:`~flask_jwt_extended.create_access_token` or
212212
:func:`~flask_jwt_extended.create_refresh_token`.
213213
@@ -224,7 +224,7 @@ def additional_headers_loader(self, callback):
224224
"""
225225
This decorator sets the callback function used to add additional headers
226226
when creating a JWT. The headers returned by this function will be merged
227-
with any headers passed in via the `additional_headers` argument to
227+
with any headers passed in via the ``additional_headers`` argument to
228228
:func:`~flask_jwt_extended.create_access_token` or
229229
:func:`~flask_jwt_extended.create_refresh_token`.
230230
@@ -311,7 +311,7 @@ def needs_fresh_token_loader(self, callback):
311311
"""
312312
This decorator sets the callback function for returning a custom
313313
response when a valid and non-fresh token is used on an endpoint
314-
that is marked as `fresh=True`.
314+
that is marked as ``fresh=True``.
315315
316316
The decorated function must take **two** arguments.
317317
@@ -351,8 +351,8 @@ def token_in_blocklist_loader(self, callback):
351351
352352
The second argument is a dictionary containing the payload data of the JWT.
353353
354-
The decorated function must be return `True` if the token has been
355-
revoked, `False` otherwise.
354+
The decorated function must be return ``True`` if the token has been
355+
revoked, ``False`` otherwise.
356356
"""
357357
self._token_in_blocklist_callback = callback
358358
return callback
@@ -384,8 +384,8 @@ def token_verification_loader(self, callback):
384384
385385
The second argument is a dictionary containing the payload data of the JWT.
386386
387-
The decorated function must return `True` if the token is valid, or
388-
`False` otherwise.
387+
The decorated function must return ``True`` if the token is valid, or
388+
``False`` otherwise.
389389
"""
390390
self._token_verification_callback = callback
391391
return callback
@@ -439,7 +439,7 @@ def user_lookup_loader(self, callback):
439439
440440
The decorated function can return any python object, which can then be
441441
accessed in a protected endpoint. If an object cannot be loaded, for
442-
example if a user has been deleted from your database, `None` must be
442+
example if a user has been deleted from your database, ``None`` must be
443443
returned to indicate that an error occurred loading the user.
444444
"""
445445
self._user_lookup_callback = callback

flask_jwt_extended/utils.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get_jwt():
1414
"""
1515
In a protected endpoint, this will return the python dictionary which has
1616
the payload of the JWT that is accessing the endpoint. If no JWT is present
17-
due to `jwt_required(optional=True)`, an empty dictionary is returned.
17+
due to ``jwt_required(optional=True)``, an empty dictionary is returned.
1818
1919
:return:
2020
The payload (claims) of the JWT in the current request
@@ -32,7 +32,7 @@ def get_jwt_header():
3232
"""
3333
In a protected endpoint, this will return the python dictionary which has
3434
the header of the JWT that is accessing the endpoint. If no JWT is present
35-
due to `jwt_required(optional=True)`, an empty dictionary is returned.
35+
due to ``jwt_required(optional=True)``, an empty dictionary is returned.
3636
3737
:return:
3838
The headers of the JWT in the current request
@@ -50,7 +50,7 @@ def get_jwt_identity():
5050
"""
5151
In a protected endpoint, this will return the identity of the JWT that is
5252
accessing the endpoint. If no JWT is present due to
53-
`jwt_required(optional=True)`, `None` is returned.
53+
``jwt_required(optional=True)``, ``None`` is returned.
5454
5555
:return:
5656
The identity of the JWT in the current request
@@ -67,7 +67,7 @@ def get_current_user():
6767
is configured. If the user loader callback is not being used, this will
6868
raise an error.
6969
70-
If no JWT is present due to `jwt_required(optional=True)`, `None` is returned.
70+
If no JWT is present due to ``jwt_required(optional=True)``, ``None`` is returned.
7171
7272
:return:
7373
The current user object for the JWT in the current request
@@ -97,7 +97,7 @@ def decode_token(encoded_token, csrf_value=None, allow_expired=False):
9797
Expected CSRF double submit value (optional).
9898
9999
:param allow_expired:
100-
If `True`, do not raise an error if the JWT is expired. Defaults to `False`
100+
If ``True``, do not raise an error if the JWT is expired. Defaults to ``False``
101101
102102
:return:
103103
Dictionary containing the payload of the JWT decoded JWT.
@@ -124,15 +124,15 @@ def create_access_token(
124124
125125
:param fresh:
126126
If this token should be marked as fresh, and can thus access endpoints
127-
protected with `@jwt_required(fresh=True)`. Defaults to `False`.
127+
protected with ``@jwt_required(fresh=True)``. Defaults to ``False``.
128128
129-
This value can also be a `datetime.timedelta`, which indicate
129+
This value can also be a ``datetime.timedelta``, which indicate
130130
how long this token will be considered fresh.
131131
132132
:param expires_delta:
133-
A `datetime.timedelta` for how long this token should last before it
133+
A ``datetime.timedelta`` for how long this token should last before it
134134
expires. Set to False to disable expiration. If this is None, it will use
135-
the 'JWT_ACCESS_TOKEN_EXPIRES` config value (see :ref:`Configuration Options`)
135+
the ``JWT_ACCESS_TOKEN_EXPIRES`` config value (see :ref:`Configuration Options`)
136136
137137
:param additional_claims:
138138
Optional. A hash of claims to include in the access token. These claims are
@@ -173,9 +173,9 @@ def create_refresh_token(
173173
serializable format.
174174
175175
:param expires_delta:
176-
A `datetime.timedelta` for how long this token should last before it expires.
176+
A ``datetime.timedelta`` for how long this token should last before it expires.
177177
Set to False to disable expiration. If this is None, it will use the
178-
'JWT_REFRESH_TOKEN_EXPIRES` config value (see :ref:`Configuration Options`)
178+
``JWT_REFRESH_TOKEN_EXPIRES`` config value (see :ref:`Configuration Options`)
179179
180180
:param additional_claims:
181181
Optional. A hash of claims to include in the refresh token. These claims are
@@ -246,7 +246,7 @@ def get_csrf_token(encoded_token):
246246
def set_access_cookies(response, encoded_access_token, max_age=None):
247247
"""
248248
Modifiy a Flask Response to set a cookie containing the access JWT.
249-
Also sets the corresponding CSRF cookies if `JWT_CSRF_IN_COOKIES` is `True`
249+
Also sets the corresponding CSRF cookies if ``JWT_CSRF_IN_COOKIES`` is ``True``
250250
(see :ref:`Configuration Options`)
251251
252252
:param response:
@@ -257,8 +257,8 @@ def set_access_cookies(response, encoded_access_token, max_age=None):
257257
258258
:param max_age:
259259
The max age of the cookie. If this is None, it will use the
260-
`JWT_SESSION_COOKIE` option (see :ref:`Configuration Options`). Otherwise,
261-
it will use this as the cookies `max-age` and the JWT_SESSION_COOKIE option
260+
``JWT_SESSION_COOKIE`` option (see :ref:`Configuration Options`). Otherwise,
261+
it will use this as the cookies ``max-age`` and the JWT_SESSION_COOKIE option
262262
will be ignored. Values should be the number of seconds (as an integer).
263263
"""
264264
response.set_cookie(
@@ -288,7 +288,7 @@ def set_access_cookies(response, encoded_access_token, max_age=None):
288288
def set_refresh_cookies(response, encoded_refresh_token, max_age=None):
289289
"""
290290
Modifiy a Flask Response to set a cookie containing the refresh JWT.
291-
Also sets the corresponding CSRF cookies if `JWT_CSRF_IN_COOKIES` is `True`
291+
Also sets the corresponding CSRF cookies if ``JWT_CSRF_IN_COOKIES`` is ``True``
292292
(see :ref:`Configuration Options`)
293293
294294
:param response:
@@ -299,8 +299,8 @@ def set_refresh_cookies(response, encoded_refresh_token, max_age=None):
299299
300300
:param max_age:
301301
The max age of the cookie. If this is None, it will use the
302-
`JWT_SESSION_COOKIE` option (see :ref:`Configuration Options`). Otherwise,
303-
it will use this as the cookies `max-age` and the JWT_SESSION_COOKIE option
302+
``JWT_SESSION_COOKIE`` option (see :ref:`Configuration Options`). Otherwise,
303+
it will use this as the cookies ``max-age`` and the JWT_SESSION_COOKIE option
304304
will be ignored. Values should be the number of seconds (as an integer).
305305
"""
306306
response.set_cookie(

flask_jwt_extended/view_decorators.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ def _verify_token_is_fresh(jwt_header, jwt_data):
3535

3636
def verify_jwt_in_request(optional=False, fresh=False, refresh=False, locations=None):
3737
"""
38-
Verify that a valid JWT is present in the request, unless `optional=True` in
38+
Verify that a valid JWT is present in the request, unless ``optional=True`` in
3939
which case no JWT is also considered valid.
4040
4141
:param optional:
42-
If `True`, do not raise an error if no JWT is present in the request.
43-
Defaults to `False`.
42+
If ``True``, do not raise an error if no JWT is present in the request.
43+
Defaults to ``False``.
4444
4545
:param fresh:
46-
If `True`, require a JWT marked as `fresh` in order to be verified.
47-
Defaults to `False`.
46+
If ``True``, require a JWT marked as ``fresh`` in order to be verified.
47+
Defaults to ``False``.
4848
4949
:param refresh:
50-
If `True`, require a refresh JWT to be verified. If `False` require an access
51-
JWT to be verified. Defaults to `False`.
50+
If ``True``, require a refresh JWT to be verified. If ``False`` require an access
51+
JWT to be verified. Defaults to ``False``.
5252
5353
:param locations:
5454
A list of locations to look for the JWT in this request, for example:
55-
`['headers', 'cookies']`. Defaluts to `None` which indicates that JWTs
56-
will be looked for in the locations defined by the `JWT_TOKEN_LOCATION`
55+
``['headers', 'cookies']``. Defaluts to ``None`` which indicates that JWTs
56+
will be looked for in the locations defined by the ``JWT_TOKEN_LOCATION``
5757
configuration option.
5858
"""
5959
if request.method in config.exempt_methods:
@@ -90,21 +90,21 @@ def jwt_required(optional=False, fresh=False, refresh=False, locations=None):
9090
endpoint can be called.
9191
9292
:param optional:
93-
If `True`, allow the decorated endpoint to be if no JWT is present in the
94-
request. Defaults to `False`.
93+
If ``True``, allow the decorated endpoint to be if no JWT is present in the
94+
request. Defaults to ``False``.
9595
9696
:param fresh:
97-
If `True`, require a JWT marked with `fresh` to be able to access this
98-
endpoint. Defaults to `False`.
97+
If ``True``, require a JWT marked with ``fresh`` to be able to access this
98+
endpoint. Defaults to ``False``.
9999
100100
:param refresh:
101-
If `True`, requires a refresh JWT to access this endpoint. If `False`,
102-
requires an access JWT to access this endpoint. Defaults to `False`.
101+
If ``True``, requires a refresh JWT to access this endpoint. If ``False``,
102+
requires an access JWT to access this endpoint. Defaults to ``False``.
103103
104104
:param locations:
105105
A list of locations to look for the JWT in this request, for example:
106-
`['headers', 'cookies']`. Defaluts to `None` which indicates that JWTs
107-
will be looked for in the locations defined by the `JWT_TOKEN_LOCATION`
106+
``['headers', 'cookies']``. Defaluts to ``None`` which indicates that JWTs
107+
will be looked for in the locations defined by the ``JWT_TOKEN_LOCATION``
108108
configuration option.
109109
"""
110110

0 commit comments

Comments
 (0)