Skip to content

Commit bb4f81a

Browse files
committed
Initial commit: django-tenant-authx v0.1.0 - Tenant-aware auth for Django multi-tenant SaaS
0 parents  commit bb4f81a

59 files changed

Lines changed: 7794 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.10", "3.11", "3.12", "3.13"]
15+
django-version: ["4.2", "5.2", "6.0"]
16+
exclude:
17+
- python-version: "3.10"
18+
django-version: "5.2"
19+
- python-version: "3.10"
20+
django-version: "6.0"
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install "Django==${{ matrix.django-version }}.*"
34+
pip install -e ".[dev,drf]"
35+
36+
- name: Run tests
37+
run: |
38+
pytest tests/ -v
39+
40+
- name: Run Security Audit
41+
run: |
42+
python tests/security_audit.py

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Django
7+
*.log
8+
local_settings.py
9+
db.sqlite3
10+
db.sqlite3-journal
11+
media/
12+
13+
# Distribution / Packaging
14+
dist/
15+
build/
16+
*.egg-info/
17+
18+
# Unit test / coverage reports
19+
htmlcov/
20+
.tox/
21+
.nox/
22+
.coverage
23+
.coverage.*
24+
.cache
25+
nosetests.xml
26+
coverage.xml
27+
*.cover
28+
*.py,cover
29+
.hypothesis/
30+
.pytest_cache/
31+
cover/
32+
33+
# Environments
34+
.env
35+
.venv
36+
env/
37+
venv/
38+
ENV/
39+
env.bak/
40+
venv.bak/
41+
42+
# IDEs
43+
.vscode/
44+
.idea/
45+
*.swp
46+
*.swo
47+
48+
# MacOS
49+
.DS_Store
50+
51+
# Agent / Tooling
52+
.antigravity/
53+
.gemini/
54+
55+
# Test Databases
56+
test_db.sqlite3
57+
demo_db.sqlite3
58+
*.sqlite3
59+
60+
# Temporary / Demo files
61+
demo_test.py

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.0] - 2026-01-18
9+
10+
### Added
11+
12+
- Core `Tenant`, `TenantMembership`, `Role`, and `Permission` models.
13+
- `TenantAwareAuthBackend` for authenticating users within tenants.
14+
- `TenantResolutionMiddleware` for identifying tenants from requests.
15+
- `TenantUser` helper for easy permission checking.
16+
- View decorators: `@tenant_login_required`, `@tenant_permission_required`, `@tenant_role_required`.
17+
- DRF integration with `TenantTokenAuthentication` and permission classes.
18+
- Comprehensive test suite with property-based testing and security audit.
19+
- Django 4.2 LTS, 5.2 LTS, and 6.0 support.

CODE_OF_CONDUCT.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex, gender identity and expression, level of
9+
experience, education, socio-economic status, nationality, personal appearance,
10+
race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
- Using welcoming and inclusive language
18+
- Being respectful of differing viewpoints and experiences
19+
- Gracefully accepting constructive criticism
20+
- Focusing on what is best for the community
21+
- Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
- The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
- Trolling, insulting/derogatory comments, and personal or political attacks
28+
- Public or private harassment
29+
- Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
- Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Enforcement
35+
36+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
37+
reported by contacting the project team at rajidkk34@gmail.com. All
38+
complaints will be reviewed and investigated and will result in a response that
39+
is deemed necessary and appropriate to the circumstances. The project team is
40+
obligated to maintain confidentiality with regard to the reporter of an incident.

CONTRIBUTING.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Contributing to django-tenant-authx
2+
3+
Thank you for your interest in contributing to `django-tenant-authx`! We welcome contributions from everyone.
4+
5+
## Getting Started
6+
7+
1. **Fork the repository** on GitHub.
8+
2. **Clone your fork** locally:
9+
```bash
10+
git clone https://github.com/kkrajid/django-tenant-authx.git
11+
cd django-tenant-authx
12+
```
13+
3. **Set up a virtual environment**:
14+
```bash
15+
python -m venv venv
16+
source venv/bin/activate # On Windows: venv\Scripts\activate
17+
```
18+
4. **Install dependencies**:
19+
```bash
20+
pip install -e ".[dev,drf]"
21+
```
22+
23+
## Running Tests
24+
25+
We use `tox` to run tests across multiple environments.
26+
27+
```bash
28+
# Run all tests
29+
tox
30+
31+
# Run only unit tests
32+
pytest tests/
33+
34+
# Run security audit
35+
python tests/security_audit.py
36+
```
37+
38+
## Development Standards
39+
40+
- **Code Style**: We use `black` and `isort`. Run `tox -e lint` to check.
41+
- **Type Hints**: All new code must be fully typed. Run `tox -e typecheck` to verify.
42+
- **Tests**: New features must include tests. We encourage property-based testing with Hypothesis.
43+
44+
## Pull Request Process
45+
46+
1. Create a new branch for your feature or fix.
47+
2. Write tests covering your changes.
48+
3. Ensure all tests pass matching the project standards.
49+
4. Update the documentation if necessary.
50+
5. Submit a Pull Request with a clear description of the changes.
51+
52+
## Code of Conduct
53+
54+
Please note that this project is released with a [Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 RAJID K K
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
include LICENSE
2+
include README.md
3+
include CHANGELOG.md
4+
include pyproject.toml
5+
6+
recursive-include tenant_authx *.py
7+
include tenant_authx/py.typed
8+
recursive-include tenant_authx/migrations *.py
9+
10+
global-exclude __pycache__
11+
global-exclude *.py[cod]
12+
global-exclude .DS_Store

0 commit comments

Comments
 (0)