Skip to content

Commit d4995dc

Browse files
authored
Merge pull request #17 from justmobilize/remove-secrets-usage
Remove secrets usage
2 parents ee24e6f + cdf7501 commit d4995dc

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

README.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,11 @@ Generating encoded JWT
6969

7070
.. code-block:: python
7171
72+
from os import getenv
7273
import adafruit_jwt
73-
# Import Private RSA key from a secrets.py file
74-
try:
75-
from secrets import secrets
76-
except ImportError:
77-
print("WiFi secrets are kept in secrets.py, please add them there!")
78-
raise
74+
75+
# Import Private RSA key from a settings.toml file
76+
private_key = getenv["private_key"]
7977
8078
# Create JWT Claims
8179
claims = {"iss": "joe",
@@ -85,7 +83,7 @@ Generating encoded JWT
8583
8684
# Generate JWT, sign with RSA private key and RS-256
8785
encoded_jwt = adafruit_jwt.JWT.generate(
88-
claims, secrets["private_key"], algo="RS256")
86+
claims, private_key, algo="RS256")
8987
print("Encoded JWT: ", encoded_jwt)
9088
9189

examples/jwt_simpletest.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
from os import getenv
45
import adafruit_jwt
56

6-
# Get private RSA key from a secrets.py file
7-
try:
8-
from secrets import secrets
9-
except ImportError:
10-
print("WiFi secrets are kept in secrets.py, please add them there!")
11-
raise
7+
# Get private RSA key from a settings.toml file
8+
private_key = getenv("private_key")
129

1310
# Run jwt_simpletest_secrets.py to generate the private key
14-
if "private_key" not in secrets:
11+
if not private_key:
1512
raise KeyError("Run jwt_simpletest_secrets.py to generate the private key!")
1613

1714
# Sample JWT Claims
1815
claims = {"iss": "joe", "exp": 1300819380, "name": "John Doe", "admin": True}
1916

2017
# Generate a JWT
2118
print("Generating JWT...")
22-
encoded_jwt = adafruit_jwt.JWT.generate(claims, secrets["private_key"], algo="RS256")
19+
encoded_jwt = adafruit_jwt.JWT.generate(claims, private_key, algo="RS256")
2320
print("Encoded JWT: ", encoded_jwt)
2421

2522
# Validate a provided JWT

examples/jwt_simpletest_secrets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
===================================================================
99
1010
Generates RSA keys and decodes them using python-rsa
11-
for use with a CircuitPython secrets file.
11+
for use with a CircuitPython settings.toml file.
1212
1313
This script is designed to run on a computer,
1414
NOT a CircuitPython device.
@@ -36,5 +36,5 @@
3636
print("No file named rsa_private.pem found in directory.")
3737
pk = rsa.PrivateKey.load_pkcs1(private_key)
3838

39-
print("Copy and paste this into your secrets.py file:\n")
40-
print('"private_key": ' + str(pk)[10:] + ",")
39+
print("Copy and paste this into your settings.toml file:\n")
40+
print(f'private_key="{str(pk)[10:]}"')

0 commit comments

Comments
 (0)