Simple test

Ensure your device works with this simple test.

examples/jwt_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4from os import getenv
 5
 6import adafruit_jwt
 7
 8# Get private RSA key from a settings.toml file
 9private_key = getenv("private_key")
10
11# Run jwt_simpletest_secrets.py to generate the private key
12if not private_key:
13    raise KeyError("Run jwt_simpletest_secrets.py to generate the private key!")
14
15# Sample JWT Claims
16claims = {"iss": "joe", "exp": 1300819380, "name": "John Doe", "admin": True}
17
18# Generate a JWT
19print("Generating JWT...")
20encoded_jwt = adafruit_jwt.JWT.generate(claims, private_key, algo="RS256")
21print("Encoded JWT: ", encoded_jwt)
22
23# Validate a provided JWT
24print("Decoding JWT...")
25decoded_jwt = adafruit_jwt.JWT.validate(encoded_jwt)
26print(f"JOSE Header: {decoded_jwt[0]}\nJWT Claims: {decoded_jwt[1]}")