Skip to main content

A django app model user proxy

Project description

AuthProxyApp is a Django app containing a single User Proxy model, which is shared between multiple Django instances.

The purpose of this Proxy model is to access a single shared “Users” database between Django applications, with no explicit foreign relations.

It currently operates with a modified User implementation featuring a UUID as a PK, you can easily implement this by creating your own AbstractUser implementation, and storing all users and permissions in a single “Users” database.

Quick start

  1. Add “auth_proxy” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'auth_proxy'
    ]
  2. Run python manage.py migrate to create the auth_proxy model.

  3. To use the proxy, use auth_proxy.models.UserProxy on foreign relations (like OneToOne, ManyToMany, ManyToOne), instead of django.contrib.auth.models.User. Remember that you’re responsible of creating these proxies, unless you use the optional middlewares.

Optional:

  1. If you wish to use the Middlewares, include them in settings like this:

    MIDDLEWARE_CLASSES = (
        ...
        'auth_proxy.middleware.GenerateUserProxy',
        'auth_proxy.middleware.AddUserProxyToRequest'
    )

GenerateUserProxy will create the UserProxy on user login, and AddUserProxyToRequest will add the UserProxy to the request, where it can be obtained like this: request.user_proxy.

  1. An user router is included. It will route the following labels:

    "admin",
    "auth",
    "profiles",
    "sessions",
    "oauth2_provider",
    "contenttypes"

To a database called users, which you should define in settings (refer to https://docs.djangoproject.com/en/4.0/topics/db/multi-db/ for more instructions). To use this router, define the following in settings:

DATABASE_ROUTERS = [
    ...
    'auth_proxy.routers.UsersRouter'
]

Note that upper-most routers will have more importance to Django. If you wish to ensure the router will do its intended purpose, insert it in the first position.

Requirements

This UserProxy is intended to be a shared local reference to a User object found in a separate database. This architecture allows multiple Django instances to share the same Users, and permissions, while retaining the ability to reference User models.

Hence, a shared database is needed, and it should be declared as “users” in all django instances. And a custom User model should be declared, with UUID as primary key.

TODO

  • REST endpoints to manage UserProxy instances

  • Erase UserProxy instances when Users are deleted

Building

Run python -m build

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-user-proxy-1.2.6.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

django_user_proxy-1.2.6-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file django-user-proxy-1.2.6.tar.gz.

File metadata

  • Download URL: django-user-proxy-1.2.6.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for django-user-proxy-1.2.6.tar.gz
Algorithm Hash digest
SHA256 1a2bd0a8dc8d8ed542307b86c21259f8a1fa3f379993fdd823da98a85780a4e9
MD5 49720a15ca100170191f9ac033b98a73
BLAKE2b-256 b699bcdc7ede2dc5694affeb9e2f810cf90a1476b76f3d17e86e7c6faca7413c

See more details on using hashes here.

File details

Details for the file django_user_proxy-1.2.6-py3-none-any.whl.

File metadata

  • Download URL: django_user_proxy-1.2.6-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for django_user_proxy-1.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b9fc3eb78c220be3218ed758aea3889b37f9b53fe0d058e356c948ec6233ccf5
MD5 e5fb289f2bf9e7db3583bdbb6fe53f93
BLAKE2b-256 1596e98af5e1817242937bdf813913eeb71dba0cabf9e57b873c0a280a8cb240

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