https://github.com/yezz123/authx
Ready-to-use and customizable Authentications and Oauth2 management for FastAPI β¨
https://github.com/yezz123/authx
authentification authorization backend fastapi jwt pydantic python starlette
Last synced: 28 days ago
JSON representation
Ready-to-use and customizable Authentications and Oauth2 management for FastAPI β¨
- Host: GitHub
- URL: https://github.com/yezz123/authx
- Owner: yezz123
- License: mit
- Created: 2021-08-23T16:18:04.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-09-15T21:38:16.000Z (5 months ago)
- Last Synced: 2025-09-15T23:29:17.431Z (5 months ago)
- Topics: authentification, authorization, backend, fastapi, jwt, pydantic, python, starlette
- Language: Python
- Homepage: https://authx.yezz.me/
- Size: 3.41 MB
- Stars: 989
- Watchers: 16
- Forks: 55
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
- awesome-morocco - AuthX - A customizable Authentications and Oauth2 management for FastAPI by [@yezz123](https://github.com/yezz123) (Uncategorized / Uncategorized)
README
# AuthX
Ready-to-use and customizable Authentications and Oauth2 management for FastAPI β‘
---
| Project | Status |
|---------|--------|
| CI | [](https://github.com/yezz123/authx/actions/workflows/ci.yml) [](https://results.pre-commit.ci/latest/github/yezz123/authx/main) [](https://codecov.io/gh/yezz123/authx) |
| Meta | [](https://pypi.org/project/authx) [](https://pepy.tech/project/authx) [](https://pydantic.dev) [](https://github.com/astral-sh/ruff) [](https://sonarcloud.io/summary/new_code?id=yezz123_authx) |
---
**Source Code**:
**Documentation**:
---
Add a fully featured authentication and authorization system to your [FastAPI](https://fastapi.tiangolo.com/) project. **AuthX** is designed to be simple, customizable, and secure.
## Installation
```bash
pip install authx
```
## Quick Start
```python
from fastapi import FastAPI, Depends, HTTPException
from authx import AuthX, AuthXConfig
app = FastAPI()
config = AuthXConfig(
JWT_SECRET_KEY="your-secret-key", # Change this!
JWT_TOKEN_LOCATION=["headers"],
)
auth = AuthX(config=config)
auth.handle_errors(app)
@app.post("/login")
def login(username: str, password: str):
if username == "test" and password == "test":
token = auth.create_access_token(uid=username)
return {"access_token": token}
raise HTTPException(401, detail="Invalid credentials")
@app.get("/protected", dependencies=[Depends(auth.access_token_required)])
def protected():
return {"message": "Hello World"}
```
**Test it:**
```bash
# Get a token
curl -X POST "http://localhost:8000/login?username=test&password=test"
# Access protected route
curl -H "Authorization: Bearer " http://localhost:8000/protected
```
## Features
- Support for Python 3.9+ and Pydantic 2
- JWT authentication with multiple token locations:
- Headers (Bearer token)
- Cookies (with CSRF protection)
- Query parameters
- JSON body
- Access and refresh token support
- Token freshness for sensitive operations
- Token blocklist/revocation
- Extensible error handling
### Extra Features
Install [`authx-extra`](https://github.com/yezz123/authx-extra) for additional features:
```bash
pip install authx-extra
```
- Redis session store and cache
- HTTP caching
- Performance profiling with pyinstrument
- Prometheus metrics
**Note:** Check [Release Notes](https://authx.yezz.me/release/).
## Contributors and Sponsors
[](#contributors-)
Thanks goes to these wonderful people
([emoji key](https://allcontributors.org/docs/en/emoji-key)):

Yasser Tahiri
π» π π§ π

Abderrahim SOUBAI-ELIDRISI
π π

Ismail Ghallou
π» π‘οΈ

MojixCoder
π» π

StΓ©phane Raimbault
π» π

theoohoho
π

Yogesh Upadhyay
π

Roman
π

Alvaro Lopez Ortega
π

Devy Santo
π

pg365
π

Jorrit
π¦

Callam
π»

Maxim
π»

Suyog Shimpi
π»

NeViNez
π
This project follows the
[all-contributors](https://github.com/all-contributors/all-contributors)
specification. Contributions of any kind welcome!
## License
This project is licensed under the terms of the MIT License.