Skip to main content
DjanQuiltDB

djanquiltdb-plugin-oauth-toolkit

PyPI Supported Python versions Supported Django versions Supported PostgreSQL versions CI Documentation Coverage BSD-3-Clause licence

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.12 to 3.15

  • Django 5.2, 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.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djanquiltdb-plugin-oauth-toolkit 1.1.0
File Size Uploaded Provenance Actions
djanquiltdb_plugin_oauth_toolkit-1.1.0.tar.gz 49.1 kB With provenance Details for djanquiltdb_plugin_oauth_toolkit-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for djanquiltdb-plugin-oauth-toolkit 1.1.0
File Interpreter ABI Platform Actions
djanquiltdb_plugin_oauth_toolkit-1.1.0-py3-none-any.whl Python 3 none any Details for djanquiltdb_plugin_oauth_toolkit-1.1.0-py3-none-any.whl

Total release size: 74.0 kB

Release files / djanquiltdb_plugin_oauth_toolkit-1.1.0.tar.gz

Download URL djanquiltdb_plugin_oauth_toolkit-1.1.0.tar.gz
Size 49.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4ac8ad00770133cb1332ee4728a541c5fb1b2bab26f6b932c12e8b92f23850fd
BLAKE2b-256 checksum
How to use checksums
1f2ccc5e03637c6f72810ac5c90daae033772f7589cfc8bb9412959fcf61b601
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 12, 2026.

Transparency log

Release files / djanquiltdb_plugin_oauth_toolkit-1.1.0-py3-none-any.whl

Download URL djanquiltdb_plugin_oauth_toolkit-1.1.0-py3-none-any.whl
Size 24.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
811df5c6f3e87078699972a99ff1edea0d3a755bc59efc6c20bcfc5fa3795c15
BLAKE2b-256 checksum
How to use checksums
0dfb5bbadd9b8ac19b890c5f1aaaeb1477bec14e4b28b93e52ea704b8ffe779a
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 12, 2026.

Transparency log

Security for djanquiltdb-plugin-oauth-toolkit 1.1.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.

Select from 2 files

Attestation for djanquiltdb_plugin_oauth_toolkit-1.1.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 12, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page