@@ -16,13 +16,12 @@ Introduction
16
16
JSON Web Token (JWT) Authentication module for CircuitPython. JSON Web Tokens are an open, industry standard
17
17
`RFC 7519 <https://tools.ietf.org/html/rfc7519 >`_ method for representing claims securely between two parties.
18
18
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" `)
21
21
* RS256/SHA-256 (via `Adafruit_CircuitPython_RSA <https://github.com/adafruit/Adafruit_CircuitPython_RSA >`_)
22
22
* RS384/SHA-384 (via `Adafruit_CircuitPython_RSA <https://github.com/adafruit/Adafruit_CircuitPython_RSA >`_)
23
23
* RS512/SHA-512 (via `Adafruit_CircuitPython_RSA <https://github.com/adafruit/Adafruit_CircuitPython_RSA >`_)
24
24
25
-
26
25
Dependencies
27
26
=============
28
27
This driver depends on:
@@ -65,9 +64,38 @@ To install in a virtual environment in your current project:
65
64
Usage Example
66
65
=============
67
66
67
+ Generating encoded JWT
68
+
68
69
.. code-block :: python
69
70
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
70
94
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: {} \n JWT Claims: {} ' .format(decoded_jwt[0 ], decoded_jwt[1 ]))
71
99
72
100
Contributing
73
101
============
0 commit comments