`FastAPI` extension for JTW Auth
Project description
fastapi-jwt
Native FastAPI extension for JWT auth
Documentation: https://k4black.github.io/fastapi-jwt/
Source Code: https://github.com/k4black/fastapi-jwt/
Installation
pip install fastapi-jwt
Usage
This library made in fastapi style, so it can be used as standard security features
from fastapi import FastAPI, Security
from fastapi_jwt import JwtAuthorizationCredentials, JwtAccessBearer
app = FastAPI()
access_security = JwtAccessBearer(secret_key="secret_key", auto_error=True)
@app.post("/auth")
def auth():
subject = {"username": "username", "role": "user"}
return {"access_token": access_security.create_access_token(subject=subject)}
@app.get("/users/me")
def read_current_user(
credentials: JwtAuthorizationCredentials = Security(access_security),
):
return {"username": credentials["username"], "role": credentials["role"]}
For more examples see (usage docs)[./docs/docs/user_guide.md]
Alternatives
-
FastAPI docs suggest writing it manually, but
- code duplication
- opportunity for bugs
-
There is nice fastapi-jwt-auth, but
- poorly supported
- not "fastapi-style" (not native functions parameters)
FastAPI Integration
There it is open and maintained Pull Request #3305 to the fastapi
repo. Currently, not considered.
Requirements
fastapi
python-jose[cryptography]
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for fastapi_jwt-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2773d2fa66e54ad1d7df892140936e1dfd0e1c4be1fd57a04b56e5f7d246cd0 |
|
MD5 | e5c3e11fc166f1659c0e8aeee369135e |
|
BLAKE2b-256 | 270968b404286a1b14b07d94957b7d3c8c454aaf71938f418c7e015020b5c2e7 |