FastAPI Plugin for reusable JWT Authentication Management
Project description
fastjwt
FastJWT is a FastAPI Plugin for reusable JWT Authentication Management. fastjwt enables easy JSON Web Tokens management within your FastAPI application.
fastjwt is heavily inspired from its Flask equivalent Flask-JWT-Extended, special thanks to @vimalloc fot the amazing work.
Documentation: https://ocarinow.github.io/fastjwt/
Features
- Encode/Decode JWT for application Authentication
- Automatic JWT detection in request
- JWT in Headers
- JWT in Cookies
- JWT in Query strings
- JWT in JSON Body
- Implicit/Explicit token refresh mechanism
- Freshness state of token
- Route protection
- Token type based protection (access/refresh)
- Token freshness protection
- Partial route protection
- Handle custom user logic for revoked token validation
- Handle custom logic for token recipient retrieval (ORM, pydantic serialization...)
- Provide FastAPI compliant dependency injection API
- Automatic error handling
- Scope Management (WIP)
Setup
Requirements
FastJWT is built on top of the following dependencies:
- FastAPI as web framework
- Pydantic as data validation
- PyJWT as python implementation of the JSON Web Token standard
FastJWT also relies on typing-extensions
for backward compatibility (python3.9)
Note
FastAPI, while required for fastjwt, is not declared as a dependency and must be installed prior with
pip install fastapi
Install
# With pip
pip install fastjwt
# With poetry
poetry add fastjwt
# With pipenv
pipenv install fastjwt
Example
from fastapi import FastAPI, Depends
from fastjwt import FastJWT
app = FastAPI()
security = FastJWT()
@app.get('/login')
def login():
return security.create_access_token(uid='foo')
@app.get('/protected', dependencies=[Depends(security.access_token_required())])
def protected():
return "This is a protected endpoint"
Development
WORK IN PROGRESS
The development guide is not available yet
Contributing
WORK IN PROGRESS
The contribution guide is not available yet
License
This project is open source under MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fastjwt-0.4.1.tar.gz
.
File metadata
- Download URL: fastjwt-0.4.1.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.8 Linux/6.5.0-1015-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 032b644bb3df8b012ccc6b20284989752e866525a9a5bafa49d93c55abf7ee9e |
|
MD5 | 1a5f325aa10f18b2b2643b4570f7afff |
|
BLAKE2b-256 | 373e4ca625d601b168b4c87553455afd74d520f2777a41a7b5fa7950ef6180bd |
File details
Details for the file fastjwt-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: fastjwt-0.4.1-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.8 Linux/6.5.0-1015-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71d0277bc63458b869cc93e38f0e10a8d1b998501ed8cb6875634344cb5ab1bb |
|
MD5 | cc3a0c389206947edeea50f7c8ff3938 |
|
BLAKE2b-256 | e4769d81fcfbcfaebed16081582ca197f3c93139b1486070bb68a076566c9eec |