Skip to main content

Ready to use and customizable Authentications and Oauth2 management for FastAPI

Project description

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

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

Extra Features

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

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

  • Using Redis as a session store & cache.
  • Support HTTPCache.
  • Support Sessions and Pre-built CRUD functions and Instance to launch Redis.
  • Support Middleware of pyinstrument to check your service performance.
  • Support Middleware for collecting and exposing Prometheus metrics.

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

📦
Callam
Callam

💻

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

License

This project is licensed under the terms of the 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

authx-1.4.1.tar.gz (58.8 kB view details)

Uploaded Source

Built Distribution

authx-1.4.1-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file authx-1.4.1.tar.gz.

File metadata

  • Download URL: authx-1.4.1.tar.gz
  • Upload date:
  • Size: 58.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for authx-1.4.1.tar.gz
Algorithm Hash digest
SHA256 06ddad3f80ebe32ce7d97adc8915c1f64b389298849f0058a713f3b0c2c1e64a
MD5 a65b9254f1e81945d52bafdff000a6b9
BLAKE2b-256 dff99ccf53c2f31222e2caf67f1e4504a9b3d8c3a84fdf098b56031a4b127219

See more details on using hashes here.

Provenance

The following attestation bundles were made for authx-1.4.1.tar.gz:

Publisher: release.yml on yezz123/authx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file authx-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: authx-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for authx-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4d42082230125e446fd5240b9531af7726d7d69370bfc5aedd6fafeb9df6ffc9
MD5 a4c346ba691c6c89be44e7936cc7962a
BLAKE2b-256 f342ef4220b13ca3d6b7fe6c0c46cbda0923d06274b822e807a2c740be49fef3

See more details on using hashes here.

Provenance

The following attestation bundles were made for authx-1.4.1-py3-none-any.whl:

Publisher: release.yml on yezz123/authx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page