Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/yezz123/AuthX

Ready-to-use and customizable Authentications and Oauth2 management for FastAPI ✨
https://github.com/yezz123/AuthX

authentification authx fastapi hacktoberfest jwt-authentication middleware oauth pydantic python starlette

Last synced: 2 months ago
JSON representation

Ready-to-use and customizable Authentications and Oauth2 management for FastAPI ✨

Lists

README

        

# Authx



AuthX


Ready-to-use and customizable Authentications and Oauth2 management for FastAPI ⚑




lint


Package version





Test


Pydantic Version 2

---

**Source Code**:

**Documentation**:

---

Add a Fully registration and authentication or authorization system to your
[FastAPI](https://fastapi.tiangolo.com/) project. **AuthX** is designed to be as
customizable and adaptable as possible.

## Features

- [x] Support Python 3.8+ & Pydantic 2.0+.
- [x] Multiple customizable authentication backend:
- [x] JWT authentication backend included
- [x] JWT encoding/decoding for application authentication
- [x] Automatic detection of JWTs in requests:
- [x] JWTs in headers
- [x] JWTs in cookies
- [x] JWTs in query parameters
- [x] JWTs in request bodies
- [x] Cookie authentication backend included
- [x] Middleware for authentication and authorization through JWT.
- [x] Extensible Error Handling System.

### Extra Features

AuthX is designed to be as customizable and adaptable as possible.

So you need to install [`authx-extra`](https://github.com/yezz123/authx-extra) to get extra features.

- [x] Using Redis as a session store & cache.
- [x] Support HTTPCache.
- [x] Support Sessions and Pre-built CRUD functions and Instance to launch Redis.
- [x] Support Middleware of [pyinstrument](https://pyinstrument.readthedocs.io/) to check your service performance.
- [x] Support Middleware for collecting and exposing [Prometheus](https://prometheus.io/) metrics.

**Note:** Check [Release Notes](https://authx.yezz.me/release/).

## Project using

Here is a simple way to kickstart your project with AuthX:

```python
from fastapi import FastAPI, Depends, HTTPException
from authx import AuthX, AuthXConfig, RequestToken

app = FastAPI()

config = AuthXConfig(
JWT_ALGORITHM = "HS256",
JWT_SECRET_KEY = "SECRET_KEY",
JWT_TOKEN_LOCATION = ["headers"],
)

auth = AuthX(config=config)
auth.handle_errors(app)

@app.get('/login')
def login(username: str, password: str):
if username == "xyz" and password == "xyz":
token = auth.create_access_token(uid=username)
return {"access_token": token}
raise HTTPException(401, detail={"message": "Invalid credentials"})

@app.get("/protected", dependencies=[Depends(auth.get_token_from_request)])
def get_protected(token: RequestToken = Depends()):
try:
auth.verify_token(token=token)
return {"message": "Hello world !"}
except Exception as e:
raise HTTPException(401, detail={"message": str(e)}) from e
```

## Contributors and sponsors

[![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors-)

Thanks goes to these wonderful people
([emoji key](https://allcontributors.org/docs/en/emoji-key)):



Yasser Tahiri
Yasser Tahiri

πŸ’» πŸ“– 🚧 πŸš‡
Abderrahim SOUBAI-ELIDRISI
Abderrahim SOUBAI-ELIDRISI

πŸ‘€ πŸ“–
Ismail Ghallou
Ismail Ghallou

πŸ’» πŸ›‘οΈ
MojixCoder
MojixCoder

πŸ’» πŸ›
StΓ©phane Raimbault
StΓ©phane Raimbault

πŸ’» πŸ”Œ


theoohoho
theoohoho

πŸ“–
Yogesh Upadhyay
Yogesh Upadhyay

πŸ›
Roman
Roman

πŸ›
Alvaro Lopez Ortega
Alvaro Lopez Ortega

πŸ“–
Devy Santo
Devy Santo

πŸš‡

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.