Skip to main content

Ready to use and customizable Authentications and Oauth2 management for FastAPI

Project description

AuthenticationX 💫

authx

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

Test codecov PyPI version Downloads Language framework Star Badge Pypi


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

Documentation: https://authx.yezz.codes/


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

Note: This is a beta version of AuthX.

Features 🔧

  • Support Python 3.8+.
  • Extensible base user model.
  • Ready-to-use register, login, reset password and verify e-mail routes.
  • Ready-to-use Social login and Oauth2 routes. (now with Google, Facebook)
    • Soon with Microsoft, Twitter, Github, etc.
    • Ready-to-use social OAuth2 login flow
  • Dependency callable to inject current user in route
  • Pluggable password validation
    • Using Captcha Service.
  • Using Email Service. (SMTP)
  • Extensible Error Handling
  • High level API to manage users, roles and permissions
  • Using Redis as a session store & cache.
  • Customizable database backend:
  • Multiple customizable authentication backend:
    • JWT authentication backend included
    • Soon to be included Cookie authentication backend
  • Full OpenAPI schema support, even with several authentication backend.
  • Provide a Docstring for each class and function.
  • Middleware Support for Oauth2 using Authlib and Starlette.

Note: Check Release Notes.

Project using 🚀

from fastapi import FastAPI
from authx import Authentication

app = FastAPI()
auth = Authentication()

# Define your routes here
app.include_router(auth.auth_router, prefix="/api/users")
app.include_router(auth.social_router, prefix="/auth")
app.include_router(auth.password_router, prefix="/api/users")
app.include_router(auth.admin_router, prefix="/api/users")
app.include_router(auth.search_router, prefix="/api/users")

Startup 🏁

from fastapi import FastAPI
from authx import Authentication
from authx.database import MongoDBBackend, RedisBackend

app = FastAPI()
auth = Authentication()

app.include_router(auth.auth_router, prefix="/api/users")
app.include_router(auth.social_router, prefix="/auth")
app.include_router(auth.password_router, prefix="/api/users")
app.include_router(auth.admin_router, prefix="/api/users")
app.include_router(auth.search_router, prefix="/api/users")

# Set MongoDB and Redis Cache
auth.set_cache(RedisBackend) # aioredis client
auth.set_database(MongoDBBackend) # motor client

Dependency injections 📦

from fastapi import FastAPI,APIRouter, Depends
from authx import User, Authentication
from authx.database import MongoDBBackend, RedisBackend

app = FastAPI()
auth = Authentication()
router = APIRouter()


app.include_router(auth.auth_router, prefix="/api/users")
app.include_router(auth.social_router, prefix="/auth")
app.include_router(auth.password_router, prefix="/api/users")
app.include_router(auth.admin_router, prefix="/api/users")
app.include_router(auth.search_router, prefix="/api/users")

# Set MongoDB and Redis Cache
auth.set_cache(RedisBackend) # aioredis client
auth.set_database(MongoDBBackend) # motor client

# Set Anonymous User
@router.get("/anonym")
def anonym_test(user: User = Depends(auth.get_user)):
    pass

# Set Authenticated User
@router.get("/user")
def user_test(user: User = Depends(auth.get_authenticated_user)):
    pass

# Set Admin User
@router.get("/admin", dependencies=[Depends(auth.admin_required)])
def admin_test():
    pass

Dependency injections only 📦

from authx import authx
from authx.database import RedisBackend

auth = authx(#Provide Config)

# startup
auth.set_cache(RedisBackend) # aioredis

Development 🚧

Setup environment 📦

You should create a virtual environment and activate it:

python -m venv venv/
source venv/bin/activate

And then install the development dependencies:

pip install -r requirements.dev.txt

Run tests 🌝

I use Pytest to run the tests, you can run this by using a shortcut command in the Makefile:

make test

Format the code 🍂

Execute the following command to apply pre-commit formatting:

make lint

Contributors and sponsors ✨☕️

All Contributors

Thanks goes to these wonderful people (emoji key):


Yasser Tahiri

💻 📖 🚧 🚇

Abderrahim SOUBAI-ELIDRISI

👀 📖

Ismail Ghallou

💻 🛡️

talentuno LLC

💵

Cactus LLC

💵

MojixCoder

💻 🐛

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

AuthX - A FastAPI package for Auth made by a human not an AI | Product Hunt Buy Me A Coffee

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-0.2.0.tar.gz (32.7 kB view hashes)

Uploaded Source

Built Distribution

authx-0.2.0-py3-none-any.whl (40.0 kB view hashes)

Uploaded Python 3

Supported by

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