A simple HMAC-based JWT implementation for MicroPython
Project description
MicroJWT
MicroJWT is a simple implementation of JSON Web Tokens (JWT) specifically designed for use in MicroPython. This project utilizes HMAC-SHA256 for signing tokens and employs basic user information (such as username and role) within the token itself. It allows you to create secure authentication systems on embedded systems, especially microcontrollers running MicroPython, like ESP8266, ESP32, and other similar devices.
Goal of the Project
The goal of MicroJWT is to provide a lightweight, easy-to-use JWT solution for embedded systems and microcontrollers. With MicroPython being a minimalistic environment, this package aims to deliver a robust authentication mechanism without requiring heavy resources, making it ideal for IoT devices and embedded applications.
JWT is commonly used in web applications for stateless authentication. MicroJWT brings this functionality to the world of embedded systems, allowing your devices to securely authenticate with external systems or APIs.
Features
- HMAC-SHA256 Signing: Provides a secure way of signing and verifying tokens using HMAC and SHA-256.
- Lightweight: Designed with minimal overhead, making it suitable for resource-constrained devices.
- Compatibility: Works seamlessly with MicroPython, making it compatible with popular microcontrollers like ESP8266, ESP32, and others.
- Security: Supports secure token creation and verification, including expiration time (exp) to prevent token replay attacks.
Installation
To install MicroJWT, you can use pip:
for MicroPython, use the appropriate package manager like upip to install directly on your microcontroller.
upip install microjwt
Usage
Here is an example of how to create and verify a JWT token:
from microjwt.core import microjwt
# Define the secret key
secret_key = "my_secret_key"
# Create a JWT token
token = microjwt.create_token("Arman", "admin", secret_key)
# Verify the token
is_valid = microjwt.verify_token(token, secret_key)
if is_valid:
print("The token is valid.")
else:
print("The token is invalid.")
License
This project is licensed under the MIT License.
Test Images
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file microjwt-0.1.0.tar.gz.
File metadata
- Download URL: microjwt-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8714dade6138ae65e01d3743239722e8462374c7564754701879cb7f8503abe
|
|
| MD5 |
205a46e3d5ef94c1731f25a30fadb447
|
|
| BLAKE2b-256 |
3a5c7e31b73773efca7055da937d6c073c5dead4c7a27c11a058ad445f716ec9
|