Skip to content

Remove secrets usage #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)


Expand Down
13 changes: 5 additions & 8 deletions examples/jwt_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
# 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
claims = {"iss": "joe", "exp": 1300819380, "name": "John Doe", "admin": True}

# 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
Expand Down
6 changes: 3 additions & 3 deletions examples/jwt_simpletest_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:]}"')