This library will help you use JWT authentication in FastAPI!
Project description
FastJWS
Using this module you can quickly and easily perform JWT authentication. The main advantage is the use of the RSA-256 algorithm for signing tokens. The library is also great for small microservices.
Install
pip:
poetry:
Speed tests
Action | Time |
---|---|
Create token | 0.11 sec |
Verify | 0.10 sec |
Examples of using
from fastapi import FastAPI, Depends
from fastjws import SingJWT, AuthJWT
from pydantic import BaseModel
import datetime
# Open keys !!!not necessarily like here)
private_key = open('rs256.rsa', "r").read()
public_key = open('rs256.rsa.pub', "r").read()
# Creating an instance of a class.
jwt_sing = SingJWT(private_key)
jwt_auth = AuthJWT(public_key)
# Pydantic model for example, this is optional)
class AuthScheme(BaseModel):
fake_login: str
fake_password: str
app = FastAPI()
@app.post("/token")
def token(fake_data: AuthScheme):
# Retrieving data from a database.
fake_user: dict = fake_database
# Selecting the token lifetime.
expire = datetime.timedelta(minutes=15)
# Receiving a token!)
token: str = jwt_sing(fake_user, expire)
@app.get("/data")
async def get_data(token_data = Depends(jwt_auth)):
return token_data
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
fastjws-1.1.0.tar.gz
(2.9 kB
view details)
Built Distribution
File details
Details for the file fastjws-1.1.0.tar.gz
.
File metadata
- Download URL: fastjws-1.1.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ce5db201de665f1c3fc75f9e1f131e93e2bf8b55cc101cb5fe0f25f0326f4c3 |
|
MD5 | 5fadfc72059e6f1007e65e974fb1f2da |
|
BLAKE2b-256 | 51e53236e3b109d2c721b2ff21e64bb39131b18cae12a265d9828f4eb848685a |
File details
Details for the file fastjws-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: fastjws-1.1.0-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0986297b79955a74485f05120c9ffdfdaa5c6b47c0838e513b63a8230e11dd7 |
|
MD5 | 43c1bc9965b53ea734c69f1d77c819e0 |
|
BLAKE2b-256 | 4eedbd17f1691add2d1683a12d59f996fc0ca419d3f1f40df12c1a11aeedfdc5 |