blob: e423cfb29c11dba1293d079861a8060fd52c0498 (
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
|
Installation
============
You can install ``PyJWT`` with ``pip``:
.. code-block:: console
$ pip install pyjwt
Cryptographic Dependencies (Optional)
-------------------------------------
If you are planning on encoding or decoding tokens using certain digital
signature algorithms (like RSA or ECDSA), you will need to install the
cryptography_ library. This can be installed explicitly, or as a required
extra in the ``pyjwt`` requirement:
.. code-block:: console
$ pip install pyjwt[crypto]
The ``pyjwt[crypto]`` format is recommended in requirements files in
projects using ``PyJWT``, as a separate ``cryptography`` requirement line
may later be mistaken for an unused requirement and removed.
.. _legacy-deps:
Legacy Dependencies
-------------------
Some environments, most notably Google App Engine, do not allow the installation
of Python packages that require compilation of C extensions and therefore
cannot install ``cryptography``. If you can install ``cryptography``, you
should disregard this section.
If you are deploying an application to one of these environments, you may
need to use the legacy implementations of the digital signature algorithms:
.. code-block:: console
$ pip install pycrypto ecdsa
Once you have installed ``pycrypto`` and ``ecdcsa``, you can tell PyJWT to use
the legacy implementations with ``jwt.register_algorithm()``. The following
example code shows how to configure PyJWT to use the legacy implementations
for RSA with SHA256 and EC with SHA256 signatures.
.. code-block:: python
import jwt
from jwt.contrib.algorithms.pycrypto import RSAAlgorithm
from jwt.contrib.algorithms.py_ecdsa import ECAlgorithm
jwt.unregister_algorithm('RS256')
jwt.unregister_algorithm('ES256')
jwt.register_algorithm('RS256', RSAAlgorithm(RSAAlgorithm.SHA256))
jwt.register_algorithm('ES256', ECAlgorithm(ECAlgorithm.SHA256))
.. _`cryptography`: https://cryptography.io
|