File: optional_endpoints.rst

package info (click to toggle)
python-flask-jwt-extended 4.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 592 kB
  • sloc: python: 4,279; makefile: 193; sh: 6
file content (19 lines) | stat: -rw-r--r-- 846 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Partially protecting routes
===========================

There may be cases where you want to use the same route regardless of if a JWT
is present in the request or not. In these situations, you can use
:func:`~flask_jwt_extended.jwt_required` with the ``optional=True`` argument. This
will allow the endpoint to be accessed regardless of if a JWT is sent in with
the request.

If no JWT is present, :func:`~flask_jwt_extended.get_jwt` and
:func:`~flask_jwt_extended.get_jwt_header`, will return an empty dictionary.
:func:`~flask_jwt_extended.get_jwt_identity`, :attr:`~flask_jwt_extended.current_user`,
and :func:`~flask_jwt_extended.get_current_user` will return None.

If a JWT that is expired or not verifiable is in the request, an error will be
still returned like normal.


.. literalinclude:: ../examples/optional_protected_endpoints.py