A fully featured, secure, and extensible authentication system for Python Flask applications.Originally ported from the Node.js version to provide multi-language support for full-stack apps.
Project description
MBKAUTHEPY
mbkauthepy is a fully featured, secure, and extensible authentication system for Python Flask applications.
Ported from the Node.js version to provide seamless multi-language support for full-stack apps.
๐ Table of Contents
- โจ Features
- ๐ง Multi-language Support
- ๐ฆ Installation
- ๐ Quickstart
- โ๏ธ Configuration (.env)
- ๐งฉ Middleware & Decorators
- ๐งช API Endpoints
- ๐๏ธ Database Schema
- ๐ Security Notes
- ๐ License
- ๐ Contact & Support
โจ Features
| Feature | Description |
|---|---|
| ๐ง Multi-language Support | Use in both Python (mbkauthe) and JavaScript (mbkauthe via npm) |
| ๐ Secure Auth | Session-based authentication with secure cookies and optional 2FA |
| ๐งโ๐คโ๐ง Role-based Access | Decorators for validating roles and permissions on protected routes |
| ๐ 2FA Support | Time-based One-Time Password (TOTP) with pyotp |
| ๐ reCAPTCHA v2 Support | Protect login routes with Google reCAPTCHA |
| ๐ช Cookie Management | Secure session cookies with custom expiration, domain, etc. |
| ๐ PostgreSQL Integration | Optimized with connection pooling via psycopg2 |
| ๐ Password Security | Bcrypt hash support (or optional plaintext in dev/test mode) |
| ๐ง Profile Data Access | Built-in helper to fetch user profile details from DB |
๐ง Multi-language Support
This package is designed to work seamlessly with both Python and JavaScript applications.
- The JavaScript version is available on npm as
mbkauthe. - The Python version is available on PyPI as
mbkauthepy.
Repositories:
- Python Version: mbkauthepy GitHub
- JavaScript Version: mbkauthe GitHub
Contact & Contributions:
-
Maaz Waheed (Python Version)
- GitHub: @42Wor
- Email: maaz.waheed@mbktechstudio.com / wwork4287@gmail.com
-
Muhammad Bin Khalid (JavaScript Version)
- GitHub: @MIbnEKhalid
- For questions or contributions:
- Support Page: mbktechstudio.com/Support
- Email: support@mbktechstudio.com / chmuhammadbinkhalid28@gmail.com
Issues / PRs:
We welcome issues and pull requests! Feel free to contribute or ask any questions.
Note: This project is developed and maintained by Maaz Waheed and Muhammad Bin Khalid.
๐ฆ Installation
1. Python & Virtual Environment
python -m venv venv
source venv/bin/activate # Linux/macOS
# .\venv\Scripts\activate # Windows
2. Install Dependencies
pip install -r requirements.txt
3. Install mbkauthepy
pip install mbkauthepy
๐ Quickstart Example
from flask import Flask, render_template, session
from dotenv import load_dotenv
from mbkauthepy import configure_mbkauthe, validate_session
load_dotenv()
app = Flask(__name__)
app.config['SECRET_KEY'] = 'your-secret-key'
configure_mbkauthe(app)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/dashboard')
@validate_session
def dashboard():
user = session['user']
return f"Welcome {user['username']}!"
if __name__ == '__main__':
app.run(debug=True)
โ๏ธ Configuration (.env)
FLASK_SECRET_KEY=my-flask-secret
mbkautheVar='{
"APP_NAME": "MBKAUTH_PYTHON_DEMO",
"IS_DEPLOYED": "false",
"LOGIN_DB": "postgresql://username:password@host:port/database",
"MBKAUTH_TWO_FA_ENABLE": "false",
"COOKIE_EXPIRE_TIME": "2", # In days
"DOMAIN": "mbktechstudio.com", # Use your actual domain in production
"Main_SECRET_TOKEN": "your-secret-token-for-terminate-api", # Added for terminateAllSessions auth
"loginRedirectURL": "/"
}'
โ
You can override behavior by editing this JSON string directly in .env.
๐งฉ Middleware & Decorators
| Decorator | Purpose |
|---|---|
@validate_session |
Ensures valid session is active |
@check_role_permission("Role") |
Checks if user has required role |
@validate_session_and_role("Role") |
Shortcut for validating both |
@authenticate_token |
Verifies request via API token header |
Example:
from src.mbkauthe import validate_session, check_role_permission, validate_session_and_role, authenticate_token
@app.route('/admin')
@validate_session_and_role("SuperAdmin")
def admin_panel():
return "Welcome to the admin panel"
@app.route('/dashboard')
@validate_session
def dashboard():
user = session['user']
return f"Welcome {user['username']}"
@app.route('/secured-admin')
@validate_session_and_role("SuperAdmin")
def secured_admin():
return "Secured Area"
@app.route('/terminate-sessions')
@authenticate_token
def terminate_sessions():
return {"success": True}
# Example of fetching user data
data = get_user_data("johndoe", ["FullName", "email"])
๐งช API Endpoints
These are available by default after calling configure_mbkauthe(app):
| Method | Endpoint | Description |
|---|---|---|
| POST | /mbkauthe/api/login |
Authenticate and create session |
| POST | /mbkauthe/api/logout |
Terminate current session |
| POST | /mbkauthe/api/terminateAllSessions |
Clears all sessions (admin only) |
| GET | /mbkauthe/i or /mbkauthe/info or mbkauthe.mbkauthe_info |
Current package version or metadata from the installed package |
| GET | mbkauthe.login_page or /mbkauthe/login |
login page in package |
๐๏ธ Database Schema
๐ See docs/db.md for schema & setup scripts.
๐ Security Notes
- ๐ Set
EncryptedPassword: "true"for production use. - โ
Always use long random
SESSION_SECRET_KEY. - ๐ Use HTTPS in deployment (
IS_DEPLOYED: "true"). - ๐ซ Avoid plaintext passwords outside dev/testing.
Note: Encrypted password support is under development. Stay tuned for updates!
๐ License
Mozilla Public License 2.0
See LICENSE for full legal text.
๐ Contact & Support
Developed by Maaz Waheed
- GitHub: @42Wor
- Email: maaz.waheed@mbktechstudio.com / wwork4287@gmail.com
- Issues / PRs welcome!
Would you like me to generate:
- โ
A
requirements.txt - โ
The
.envtemplate - โ Diagrams (e.g., session flow, DB schema)
- โ Frontend login template in HTML?
Let me know which extras you want!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mbkauthepy-1.6.0.tar.gz.
File metadata
- Download URL: mbkauthepy-1.6.0.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
847aef6d9dfbf6938ebd0b5a2ebbda557d4fcd5df01466ebd80ff5663fee454b
|
|
| MD5 |
e405600073f3dcc79629713cb186fa1d
|
|
| BLAKE2b-256 |
64dadf07f852498f7da1224b53d4791d68743578b13ea967ba4cedf525b1d45f
|
File details
Details for the file mbkauthepy-1.6.0-py3-none-any.whl.
File metadata
- Download URL: mbkauthepy-1.6.0-py3-none-any.whl
- Upload date:
- Size: 28.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ac71f94468855bb984682e312716ab33a8e297322d16a8e9fbd3fc8f03e7cdf
|
|
| MD5 |
655de48e8365253cb579b4c6b753494f
|
|
| BLAKE2b-256 |
a52e4634fdc70041b401df071cb6292b7f815207748f9081560d479964c47c35
|