AuthX
AuthX is a versatile and reusable authentication API built to work seamlessly with both Flask and FastAPI. It supports multiple authentication methods, including traditional username/password login, OAuth 2.0 with social logins (Google, Facebook, GitHub, etc.), two-factor authentication (2FA), passwordless login, and more. AuthX is designed with security and flexibility in mind, making it easy to integrate into various applications while providing robust user management and role-based access control (RBAC).
AuthX is a reusable and modular authentication API designed to work with both Flask and FastAPI. It offers a wide range of authentication methods, making it an ideal solution for projects that require secure and flexible user authentication.
- Username/Password Authentication: Secure user registration and login with hashed passwords.
- OAuth 2.0: Support for social logins with Google, Facebook, GitHub, and more.
- Two-Factor Authentication (2FA): Optional second layer of security with OTP via SMS or email.
- Passwordless Authentication: Magic link or email link login for a seamless user experience.
- JWT Authentication: Token-based authentication for stateless sessions.
- API Key Authentication: Secure service-to-service communication using API keys.
- Role-Based Access Control (RBAC): User roles and permissions management.
- Single Sign-On (SSO): Support for enterprise-level SSO with protocols like SAML and OpenID Connect.
- Modular Design: Easily extend or customize the API to fit your specific needs.
- Python 3.8 or higher
- Flask
- FastAPI
- SQLAlchemy
- Alembic
- OAuthlib
-
Clone the repository:
git clone https://github.com/yourusername/authx.git cd authx
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.env
file in the project root with your configuration. Example:FLASK_APP=authx_flask FLASK_ENV=development SECRET_KEY=your_secret_key SQLALCHEMY_DATABASE_URI=sqlite:///authx.db
-
Run the database migrations:
flask db upgrade
-
Start the Flask server:
flask run
The API will be available at
http://127.0.0.1:5000/
. -
Explore the available endpoints and start integrating AuthX into your Flask-based project.
-
Start the FastAPI server:
uvicorn authx_fastapi:app --reload
The API will be available at
http://127.0.0.1:8000/
. -
Explore the available endpoints via the automatically generated Swagger UI at
http://127.0.0.1:8000/docs
.
- Username/Password: Register and log in users with traditional credentials.
- OAuth 2.0: Enable social logins with popular providers like Google, Facebook, and GitHub.
- 2FA: Add an extra layer of security with two-factor authentication.
- Passwordless: Allow users to log in without a password using a magic link.
- JWT: Secure API requests with token-based authentication.
- API Key: Protect your services with API key-based authentication.
You can configure various aspects of AuthX by editing the .env
file. Key configuration options include:
- Database URI: Specify the database connection string.
- Secret Key: Set the secret key for secure session management.
- OAuth Providers: Configure credentials for OAuth providers.
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.
This project is licensed under the MIT License - see the LICENSE file for details.
- Thanks to the open-source community for providing tools and libraries that made this project possible.
- Special thanks to the Flask and FastAPI teams for their amazing work on these frameworks.