Skip to main content

weenspace-auth

WeenSpace Authentication.

What this package provides

  • Django app extending the auth stack with UUID v4 identities.
  • User, organization, and account models for multi-account and multi-organization structure.
  • External identity bindings for Microsoft, Google, Apple, Zitadel, and custom OIDC-compatible providers.
  • Bridge hooks to leverage logic from the existing weenspace.auth module when present.
  • Runtime mode selection for SP, IDP, or both.

Data model overview

  • A user can belong to many organizations.
  • A user can belong to many accounts.
  • An organization can own many accounts.
  • No tenant concepts are modeled in this package.

Requirements

  • Python 3.14+
  • Django 6.1+

Install

poetry add weenspace-auth

or from local workspace:

poetry -C src/backend/weenspace-auth install

Integrate with a Django project

  1. Add app to INSTALLED_APPS:
INSTALLED_APPS = [
    # ...
    "weenspace.auth",
]
  1. Use UUID-based custom user model:
AUTH_USER_MODEL = "weenspace_auth.IdentityUser"

Note:

  • Django requires AUTH_USER_MODEL to use app_label.ModelName.
  • Keep the app label weenspace_auth in AUTH_USER_MODEL for compatibility.
  • Values like weenspace.auth.IdentityUser are not valid in Django settings.
  1. Run migrations:
python manage.py migrate
  1. OIDC endpoints exposed by this package:
/auth/oidc/<provider>/login/
/auth/oidc/<provider>/callback/
/auth/oidc/logout/
/auth/oidc/<provider>/logout/
/auth/oidc/<provider>/revoke/

Security behavior:

  • next URLs are validated and restricted to same-host URLs.
  • Invalid or external next values fall back to /.
  • Token revocation endpoint accepts POST requests only.
  1. Configure auth role mode (sp, idp, or both):
# Default is "sp"
WEENSPACE_AUTH_MODE = "sp"

# Optional explicit issuer for IDP discovery document.
WEENSPACE_AUTH_IDP_ISSUER = "https://auth.example.com/auth/oidc"

# Optional override for where IDP hooks are implemented.
WEENSPACE_AUTH_IDP_HOOKS_MODULE = "weenspace.auth"

# Keep this false in production. If true, IDP mode can run without required hooks.
WEENSPACE_AUTH_ALLOW_UNCONFIGURED_IDP = False

Mode behavior:

  • sp: exposes provider login/callback/logout/revoke endpoints.
  • idp: exposes IDP endpoints only.
  • both: exposes both SP and IDP endpoint sets.
  • Invalid WEENSPACE_AUTH_MODE values fail startup with a Django configuration error.
  • In idp or both mode, startup fails unless all required IDP hooks are configured.

IDP endpoints:

/auth/oidc/.well-known/openid-configuration
/auth/oidc/authorize/
/auth/oidc/token/
/auth/oidc/userinfo/
/auth/oidc/jwks/

IDP request handling is hook-driven through optional functions in weenspace.auth:

  • on_oidc_authorize_request(request)
  • on_oidc_token_request(request)
  • on_oidc_userinfo_request(request)
  • on_oidc_jwks_request(request)

When hooks are not defined, IDP action endpoints return 501 Not Implemented.

  1. Optional claim mapping and default assignment:
WEENSPACE_AUTH_DEFAULT_ORGANIZATION_SLUG = "default-org"
WEENSPACE_AUTH_DEFAULT_ACCOUNT_SLUG = "default-account"

WEENSPACE_AUTH_PROVIDERS = {
    "google": {
        "client_id": "...",
        "client_secret": "...",
        "issuer": "https://accounts.google.com",
        "organization_claim": "org_slug",
        "account_claim": "account_slug",
        "auto_create_org_account": True,
        "end_session_endpoint": "",
        "revocation_endpoint": "https://oauth2.googleapis.com/revoke",
        "revocation_auth_method": "client_secret_post",
    }
}
  1. Optional provider config:
WEENSPACE_AUTH_PROVIDERS = {
    "microsoft": {
        "client_id": "...",
        "client_secret": "...",
        "issuer": "https://login.microsoftonline.com/common/v2.0",
        "scopes": ["openid", "email", "profile"],
        "end_session_endpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/logout",
    },
    "google": {
        "client_id": "...",
        "client_secret": "...",
        "issuer": "https://accounts.google.com",
        "revocation_endpoint": "https://oauth2.googleapis.com/revoke",
    },
    "apple": {
        "client_id": "...",
        "client_secret": "...",
        "issuer": "https://appleid.apple.com",
        "revocation_endpoint": "https://appleid.apple.com/auth/revoke",
    },
    "zitadel": {
        "client_id": "...",
        "client_secret": "...",
        "issuer": "https://<your-zitadel-domain>",
        "end_session_endpoint": "https://<your-zitadel-domain>/oidc/v1/end_session",
        "revocation_endpoint": "https://<your-zitadel-domain>/oauth/v2/revoke",
    },
}
  1. For production migration planning when switching the user model, follow:
  • docs/AUTH_USER_MODEL_MIGRATION_ROLLOUT.md
  • docs/REPLACEMENT_READINESS_CHECKLIST.md
  • docs/ZITADEL_COMPARISON.md

Publishing

This package is prepared for publishing to PyPI via Poetry:

poetry build
poetry publish

Local development with pyenv

pyenv install -s 3.14.0
pyenv local 3.14.0
python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install poetry
poetry install
poetry run pytest

Metadata

Release files for weenspace-auth 0.1.6

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

Source distribution (sdist)

Source distribution for weenspace-auth 0.1.6
File Size Uploaded
weenspace_auth-0.1.6.tar.gz 14.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for weenspace-auth 0.1.6
File Interpreter ABI Platform
weenspace_auth-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 33.2 kB

Release files / weenspace_auth-0.1.6.tar.gz

Download URL weenspace_auth-0.1.6.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9bb36fc752477796e6b2fd7fd09f31596eb3533f34f5340c3f599c47f99b42f0
BLAKE2b-256 checksum
How to use checksums
8e7740af9995558bf4648f9d4b71f30334cc9ae03f5e712728a19c9d26ee6ae0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.0 Darwin/25.6.0

Release files / weenspace_auth-0.1.6-py3-none-any.whl

Download URL weenspace_auth-0.1.6-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d000925225e82a41d0794bf7235d66e1e442ff26b6cc30c78d473ef282ad294
BLAKE2b-256 checksum
How to use checksums
4e1f16c23aa9a44541a6cbd47942772ccfb560c28669f49db6a5bcf5351c4c6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.0 Darwin/25.6.0

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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