diff --git a/README.rst b/README.rst index 23a6159..c8e41de 100644 --- a/README.rst +++ b/README.rst @@ -69,13 +69,11 @@ Generating encoded JWT .. code-block:: python + from os import getenv import adafruit_jwt - # Import Private RSA key from a secrets.py file - try: - from secrets import secrets - except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise + + # Import Private RSA key from a settings.toml file + private_key = getenv["private_key"] # Create JWT Claims claims = {"iss": "joe", @@ -85,7 +83,7 @@ Generating encoded JWT # Generate JWT, sign with RSA private key and RS-256 encoded_jwt = adafruit_jwt.JWT.generate( - claims, secrets["private_key"], algo="RS256") + claims, private_key, algo="RS256") print("Encoded JWT: ", encoded_jwt) diff --git a/examples/jwt_simpletest.py b/examples/jwt_simpletest.py index dd50bb8..5429635 100644 --- a/examples/jwt_simpletest.py +++ b/examples/jwt_simpletest.py @@ -1,17 +1,14 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import adafruit_jwt -# Get private RSA key from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get private RSA key from a settings.toml file +private_key = getenv("private_key") # Run jwt_simpletest_secrets.py to generate the private key -if "private_key" not in secrets: +if not private_key: raise KeyError("Run jwt_simpletest_secrets.py to generate the private key!") # Sample JWT Claims @@ -19,7 +16,7 @@ # Generate a JWT print("Generating JWT...") -encoded_jwt = adafruit_jwt.JWT.generate(claims, secrets["private_key"], algo="RS256") +encoded_jwt = adafruit_jwt.JWT.generate(claims, private_key, algo="RS256") print("Encoded JWT: ", encoded_jwt) # Validate a provided JWT diff --git a/examples/jwt_simpletest_secrets.py b/examples/jwt_simpletest_secrets.py index c673c42..12f2f99 100644 --- a/examples/jwt_simpletest_secrets.py +++ b/examples/jwt_simpletest_secrets.py @@ -8,7 +8,7 @@ =================================================================== Generates RSA keys and decodes them using python-rsa -for use with a CircuitPython secrets file. +for use with a CircuitPython settings.toml file. This script is designed to run on a computer, NOT a CircuitPython device. @@ -36,5 +36,5 @@ print("No file named rsa_private.pem found in directory.") pk = rsa.PrivateKey.load_pkcs1(private_key) -print("Copy and paste this into your secrets.py file:\n") -print('"private_key": ' + str(pk)[10:] + ",") +print("Copy and paste this into your settings.toml file:\n") +print(f'private_key="{str(pk)[10:]}"')