Skip to content

Commit 7b7c527

Browse files
brentrubrentru
authored andcommitted
update README
1 parent 09b04f3 commit 7b7c527

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

README.rst

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ Introduction
1616
JSON Web Token (JWT) Authentication module for CircuitPython. JSON Web Tokens are an open, industry standard
1717
`RFC 7519 <https://tools.ietf.org/html/rfc7519>`_ method for representing claims securely between two parties.
1818

19-
This library currently supports the following signature algorithms:
20-
* No encoding, "none"
19+
This library currently supports the following signature algorithms for JWT generation and verification:
20+
* No encoding (`"none"`)
2121
* RS256/SHA-256 (via `Adafruit_CircuitPython_RSA <https://github.com/adafruit/Adafruit_CircuitPython_RSA>`_)
2222
* RS384/SHA-384 (via `Adafruit_CircuitPython_RSA <https://github.com/adafruit/Adafruit_CircuitPython_RSA>`_)
2323
* RS512/SHA-512 (via `Adafruit_CircuitPython_RSA <https://github.com/adafruit/Adafruit_CircuitPython_RSA>`_)
2424

25-
2625
Dependencies
2726
=============
2827
This driver depends on:
@@ -65,9 +64,38 @@ To install in a virtual environment in your current project:
6564
Usage Example
6665
=============
6766

67+
Generating encoded JWT
68+
6869
.. code-block:: python
6970
71+
import adafruit_jwt
72+
# Import Private RSA key from a secrets.py file
73+
try:
74+
from secrets import secrets
75+
except ImportError:
76+
print("WiFi secrets are kept in secrets.py, please add them there!")
77+
raise
78+
79+
# Create JWT Claims
80+
claims = {"iss": "joe",
81+
"exp": 1300819380,
82+
"name": "John Doe",
83+
"admin": True}
84+
85+
# Generate JWT, sign with RSA private key and RS-256
86+
encoded_jwt = adafruit_jwt.JWT.generate(
87+
claims, secrets["private_key"], algo="RS256")
88+
print("Encoded JWT: ", encoded_jwt)
89+
90+
91+
Validating a generated JWT, encoded_jwt.
92+
93+
.. code-block:: python
7094
95+
import adafruit_jwt
96+
decoded_jwt = adafruit_jwt.JWT.validate(encoded_jwt)
97+
# The decoded JWT's JOSE header and claims set are returned as a tuple
98+
print('JOSE Header: {}\nJWT Claims: {}'.format(decoded_jwt[0], decoded_jwt[1]))
7199
72100
Contributing
73101
============

0 commit comments

Comments
 (0)