djanquiltdb-plugin-oauth-toolkit
DjanQuiltDB shards a database across schemas and nodes. This library generates client ids and tokens for django-oauth-toolkit that have the mapping value of their tenant in them, which is the value that the mapping table of the project maps onto the shard of the tenant. For the tenant whose mapping value is acme, they look like OacmeI... and OacmeT...:
OAUTH2_PROVIDER = {
'CLIENT_ID_GENERATOR_CLASS': 'djanquiltdb.base.oauth_toolkit.ShardSelectorClientIdGenerator',
'ACCESS_TOKEN_GENERATOR': 'djanquiltdb.utils.oauth_toolkit.generate_access_token',
'REFRESH_TOKEN_GENERATOR': 'djanquiltdb.utils.oauth_toolkit.generate_refresh_token',
}
Its middleware reads the mapping value back from the client id or the token of each request, and enters the shard of its tenant before django-oauth-toolkit looks up the client id or the token. Put it in place of UseShardForMiddleware, after SessionMiddleware and before the toolkit’s OAuth2TokenMiddleware:
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'djanquiltdb.middleware.oauth_toolkit.OAuthToolkitUseShardForMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'oauth2_provider.middleware.OAuth2TokenMiddleware',
]
Install it through DjanQuiltDB’s extra:
pip install djanquiltdb[oauth-toolkit]
The installation guide describes each step in full. The toolkit’s models are sharded, so that each tenant has its own applications, grants and tokens. The project needs a MAPPING_MODEL, because the shard selector is the mapping value of a tenant. This example maps tenants onto shards by slug, so SHARD_SELECTOR_REGEX matches slugs:
QUILT_DB = {
...
'MAPPING_MODEL': 'myapp.models.TenantShard',
'SHARD_SELECTOR_REGEX': '[-a-z0-9]+',
'OVERRIDE_SHARDING_MODE': {
...
('oauth2_provider',): ShardingMode.SHARDED,
},
}
List the plugin in INSTALLED_APPS before oauth2_provider, so that its cleartokens command, which clears the expired tokens of every active shard, replaces the toolkit’s:
INSTALLED_APPS = [
...
'djanquiltdb_plugin_oauth_toolkit',
'oauth2_provider',
...
]
Full documentation is at https://djanquiltdb.readthedocs.io/en/latest/plugins/oauth-toolkit/index.html.
Development
This package is developed in the DjanQuiltDB repository beside djanquiltdb itself. Tests run through tox against the Postgres containers in the repository’s docker-compose.yml; see DOCKER.md at the repository root:
docker compose run --rm test tox
Requirements
Python 3.14
Django 6.0 or 6.1
PostgreSQL 17 or 18
djanquiltdb 4.6.0 or newer 4.x
django-oauth-toolkit 3.4 or newer 3.x
Metadata
Release files for djanquiltdb-plugin-oauth-toolkit 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| djanquiltdb_plugin_oauth_toolkit-1.0.0.tar.gz | 48.9 kB | With provenance | Details for djanquiltdb_plugin_oauth_toolkit-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| djanquiltdb_plugin_oauth_toolkit-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for djanquiltdb_plugin_oauth_toolkit-1.0.0-py3-none-any.whl |
Total release size: 73.7 kB
Release files / djanquiltdb_plugin_oauth_toolkit-1.0.0.tar.gz
| Download URL | djanquiltdb_plugin_oauth_toolkit-1.0.0.tar.gz |
|---|---|
| Size | 48.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd1a423b5710042ae31704b2720a7055ec46661f79689f46bd31fd35a80d7ccd
|
|
BLAKE2b-256 checksum How to use checksums |
8bae5eaa8847a7eb1ac11a373abc24e61850eefbb1a267920c773c15d5729440
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logRelease files / djanquiltdb_plugin_oauth_toolkit-1.0.0-py3-none-any.whl
| Download URL | djanquiltdb_plugin_oauth_toolkit-1.0.0-py3-none-any.whl |
|---|---|
| Size | 24.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a5803454ec3964516acca9c81ea99fc9a2027a1ddfd9467663320feed19b91c
|
|
BLAKE2b-256 checksum How to use checksums |
27c76dfd94e9418b84f8523d0c601a915126d6e267dba6848e163d2918522368
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logSecurity for djanquiltdb-plugin-oauth-toolkit 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for djanquiltdb_plugin_oauth_toolkit-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.