|
| 1 | +python-jose |
| 2 | +=========== |
| 3 | + |
| 4 | +A JOSE implementation in Python |
| 5 | + |
| 6 | +|Build Status| |Coverage Status| |
| 7 | + |
| 8 | +The JavaScript Object Signing and Encryption (JOSE) technologies - JSON |
| 9 | +Web Signature (JWS), JSON Web Encryption (JWE), JSON Web Key (JWK), and |
| 10 | +JSON Web Algorithms (JWA) - collectively can be used to encrypt and/or |
| 11 | +sign content using a variety of algorithms. While the full set of |
| 12 | +permutations is extremely large, and might be daunting to some, it is |
| 13 | +expected that most applications will only use a small set of algorithms |
| 14 | +to meet their needs. |
| 15 | + |
| 16 | +Principles |
| 17 | +---------- |
| 18 | + |
| 19 | +This is a JOSE implementation that is meant to be simple to use, both on |
| 20 | +and off of AppEngine. |
| 21 | + |
| 22 | +Examples |
| 23 | +-------- |
| 24 | + |
| 25 | +JSON Web Signature |
| 26 | +~~~~~~~~~~~~~~~~~~ |
| 27 | + |
| 28 | +JSON Web Signatures (JWS) are used to digitally sign a JSON encoded |
| 29 | +object and represent it as a compact URL-safe string. |
| 30 | + |
| 31 | +Signing tokens |
| 32 | +^^^^^^^^^^^^^^ |
| 33 | + |
| 34 | +.. code:: python |
| 35 | +
|
| 36 | + >>> from jose import jws |
| 37 | + >>> signed = jws.sign({'a': 'b'}, 'secret', algorithm='HS256') |
| 38 | + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8' |
| 39 | +
|
| 40 | +Verifying token signatures |
| 41 | +^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 42 | + |
| 43 | +.. code:: python |
| 44 | +
|
| 45 | + >>> jws.verify(signed, 'secret', algorithms=['HS256']) |
| 46 | + {'a': 'b'} |
| 47 | +
|
| 48 | +JSON Web Token |
| 49 | +~~~~~~~~~~~~~~ |
| 50 | + |
| 51 | +JSON Web Tokens (JWT) are a JWS with a set of reserved claims to be used |
| 52 | +in a standardized manner. |
| 53 | + |
| 54 | +JWT Reserved Claims |
| 55 | +^^^^^^^^^^^^^^^^^^^ |
| 56 | + |
| 57 | ++---------+--------------+--------------------+-----------------------------------------------+ |
| 58 | +| Claim | Name | Format | Usage | |
| 59 | ++=========+==============+====================+===============================================+ |
| 60 | +| 'exp' | Expiration | int | The time after which the token is invalid. | |
| 61 | ++---------+--------------+--------------------+-----------------------------------------------+ |
| 62 | +| 'nbf' | Not Before | int | The time before which the token is invalid. | |
| 63 | ++---------+--------------+--------------------+-----------------------------------------------+ |
| 64 | +| 'iss' | Issuer | str | The principal that issued the JWT. | |
| 65 | ++---------+--------------+--------------------+-----------------------------------------------+ |
| 66 | +| 'aud' | Audience | str or list(str) | The recipient that the JWT is intended for. | |
| 67 | ++---------+--------------+--------------------+-----------------------------------------------+ |
| 68 | +| 'iat' | Issued At | int | The time at which the JWT was issued. | |
| 69 | ++---------+--------------+--------------------+-----------------------------------------------+ |
| 70 | + |
| 71 | +Algorithms |
| 72 | +---------- |
| 73 | + |
| 74 | +The following algorithms are currently supported. |
| 75 | + |
| 76 | ++-------------------+---------------------------------------+ |
| 77 | +| Algorithm Value | Digital Signature or MAC Algorithm | |
| 78 | ++===================+=======================================+ |
| 79 | +| HS256 | HMAC using SHA-256 hash algorithm | |
| 80 | ++-------------------+---------------------------------------+ |
| 81 | +| HS384 | HMAC using SHA-384 hash algorithm | |
| 82 | ++-------------------+---------------------------------------+ |
| 83 | +| HS512 | HMAC using SHA-512 hash algorithm | |
| 84 | ++-------------------+---------------------------------------+ |
| 85 | +| RS256 | RSASSA using SHA-256 hash algorithm | |
| 86 | ++-------------------+---------------------------------------+ |
| 87 | +| RS384 | RSASSA using SHA-384 hash algorithm | |
| 88 | ++-------------------+---------------------------------------+ |
| 89 | +| RS512 | RSASSA using SHA-512 hash algorithm | |
| 90 | ++-------------------+---------------------------------------+ |
| 91 | + |
| 92 | +Thanks |
| 93 | +------ |
| 94 | + |
| 95 | +This library is based heavily on the work of the guys over at |
| 96 | +`PyJWT <https://github.com/jpadilla/pyjwt>`__. |
| 97 | + |
| 98 | +.. |Build Status| image:: https://travis-ci.org/mpdavis/python-jose.svg?branch=master |
| 99 | + :target: https://travis-ci.org/mpdavis/python-jose |
| 100 | +.. |Coverage Status| image:: https://coveralls.io/repos/mpdavis/python-jose/badge.svg |
| 101 | + :target: https://coveralls.io/r/mpdavis/python-jose |
0 commit comments