fastapi-jwt
FastAPI native extension, easy and simple JWT auth
Documentation: k4black.github.io/fastapi-jwt
Source Code: github.com/k4black/fastapi-jwt
Features
- OpenAPI schema generation
- Native integration with FastAPI
- Access/Refresh JWT
- JTI
- Cookie setting
Installation
You can access package fastapi-jwt in pypi
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, Response
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.post("/auth_cookie")
def auth(response: Response):
subject = {"username": "username", "role": "user"}
access_token = access_security.create_access_token(subject=subject)
access_security.set_access_cookie(response, access_token)
return {"access_token": access_token}
@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
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
fastapipython-jose[cryptography]
License
This project is licensed under the terms of the MIT license.
Metadata
Release files for fastapi-jwt-extended 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi-jwt-extended-1.0.0.tar.gz | 11.8 kB | Without provenance | Details for fastapi-jwt-extended-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_jwt_extended-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for fastapi_jwt_extended-1.0.0-py3-none-any.whl |
Total release size: 18.5 kB
Release files / fastapi-jwt-extended-1.0.0.tar.gz
| Download URL | fastapi-jwt-extended-1.0.0.tar.gz |
|---|---|
| Size | 11.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1946b77d5af3826754449f39c60b4c15aa9be8bcde62cca5d2f28712e10099a6
|
|
BLAKE2b-256 checksum How to use checksums |
a33d356f0fdeaf76d04adead471c8e92bae19e01ea980aa652bd2dd2a054f215
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.6
|
Release files / fastapi_jwt_extended-1.0.0-py3-none-any.whl
| Download URL | fastapi_jwt_extended-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84bc06b7dad318bbddff51fbd336068bab8495b34a2ed98857eb70b31091a241
|
|
BLAKE2b-256 checksum How to use checksums |
bae0764fd4a6f446666be6492cd152bbbc718ab7031a51203458c65737f4d1a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.6
|
Security for fastapi-jwt-extended 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.