yezz123 / authx

Ready-to-use and customizable Authentications and Oauth2 management for FastAPI ✨
https://authx.yezz.me/
MIT License
771 stars 48 forks source link
authentification authorization backend fastapi jwt pydantic python starlette

Authx

AuthX

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


Project Status
CI  CI  pre-commit.ci status  Codecov
Meta  Package version  Downloads  Pydantic Version 2  Ruff Quality Gate Status

Source Code: https://github.com/yezz123/authx

Documentation: https://authx.yezz.me/


Add a Fully registration and authentication or authorization system to your FastAPI project. AuthX is designed to be as customizable and adaptable as possible.

Features

Extra Features

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

So you need to install authx-extra to get extra features.

Note: Check Release Notes.

Project using

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

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

Thanks goes to these wonderful people (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

πŸš‡
pg365
pg365

πŸš‡
Jorrit
Jorrit

πŸ“¦

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This project is licensed under the terms of the MIT License.