jwt_simpletest.py
1 import adafruit_jwt 2 3 # Get private RSA key from a secrets.py file 4 try: 5 from secrets import secrets 6 except ImportError: 7 print("WiFi secrets are kept in secrets.py, please add them there!") 8 raise 9 10 # Sample JWT Claims 11 claims = {"iss": "joe", "exp": 1300819380, "name": "John Doe", "admin": True} 12 13 # Generate a JWT 14 print("Generating JWT...") 15 encoded_jwt = adafruit_jwt.JWT.generate(claims, secrets["private_key"], algo="RS256") 16 print("Encoded JWT: ", encoded_jwt) 17 18 # Validate a provided JWT 19 print("Decoding JWT...") 20 decoded_jwt = adafruit_jwt.JWT.validate(encoded_jwt) 21 print("JOSE Header: {}\nJWT Claims: {}".format(decoded_jwt[0], decoded_jwt[1]))