Skip to main content

Reusable Django app for organization-aware roles and permissions.

Project description


Django Org Authz

A reusable Django app for managing roles, permissions, and organization-based access control (RBAC). Built for multi-tenant systems to simplify role management and make authorization consistent across projects.


Features

  • 🔹 Organization-aware roles – manage users and permissions scoped by organization
  • 🔹 Fine-grained permissions – control access to models, routes, or actions
  • 🔹 Plug-and-play setup – install, migrate, and use in minutes
  • 🔹 REST API ready – works seamlessly with Django REST Framework
  • 🔹 Auth-flexible – supports both JWT and session-based authentication

Use Case

Ideal for SaaS or multi-tenant Django applications where each organization has its own users, roles, and access levels.


Installation

pip install django-org-authz

Then add it to your Django settings:

INSTALLED_APPS = [
    ...,
    'rest_framework',
    'org_authz',
]

Configuration

Ensure your Django REST Framework settings support both session and JWT authentication (optional but recommended):

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
    ],
}

Then apply migrations:

python manage.py migrate

Models Overview

Model Description
Organization Represents a tenant or company
Role Defines a role within an organization
Permission Defines an action or capability
RolePermission Connects roles to permissions
UserRole Connects users to roles in specific organizations

API Endpoints

Once installed, the package registers the following routes (using DRF’s DefaultRouter):

Endpoint Description
/api/organizations/ Manage organizations
/api/roles/ Manage roles
/api/permissions/ Manage permissions
/api/user-roles/ Assign users to roles

Usage Example

Assign a Role to a User

from org_authz.models import Organization, Role, UserRole
from django.contrib.auth.models import User

org = Organization.objects.create(name="Acme Inc", slug="acme")
user = User.objects.create_user(username="john", password="secret")
role = Role.objects.create(name="Manager", organization=org)

UserRole.objects.create(user=user, role=role, organization=org)

Protect a View with a Permission

from org_authz.decorators import require_permission

@require_permission("can_view_reports")
def reports_view(request):
    ...

This works for both session-authenticated and JWT-authenticated users.


Contributing

Contributions, feature requests, and feedback are welcome! To contribute:

git clone https://github.com/<your-username>/django-org-authz
cd django-org-authz
pip install -r requirements.txt
python manage.py test

License

This project is licensed under the MIT License – free for commercial and personal use.


Author

Victor Mwendwa Full Stack Developer vicmwe184@gmail.com


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

django_org_authz-0.1.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_org_authz-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file django_org_authz-0.1.0.tar.gz.

File metadata

  • Download URL: django_org_authz-0.1.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for django_org_authz-0.1.0.tar.gz
Algorithm Hash digest
SHA256 67de3f3a6fd5fa8a9e2d75ede594008c8213b47d940f524bded7ef503ccaf8e1
MD5 66232dc5cbfdedc3bad326dd8321e9fb
BLAKE2b-256 cc853f822fac83822469ba2987845aa7eb648dba9141664b18aecdf98415615e

See more details on using hashes here.

File details

Details for the file django_org_authz-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_org_authz-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f25a0314409171c3000145a66cbc2a70c1b2734be1d645d2eff909fb1d22c94f
MD5 cab005856220b78ccd035bdcfcdc9f35
BLAKE2b-256 cb32d4b656c404a319b5f11f3a0ba2b59c0652d824e3379248d01970ebe9b9d1

See more details on using hashes here.

Supported by

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