A Django Magic Link SSO client
Project description
magic-link-sso-django
Reusable Django integration package for the Magic Link SSO server.
Install
pip install magic-link-sso-django
Required settings
At minimum, configure:
MAGICSSO_SERVER_URL = 'http://localhost:3000'
MAGICSSO_JWT_SECRET = 'replace-me-with-a-long-random-jwt-secret'
MAGICSSO_PREVIEW_SECRET = 'replace-me-with-a-different-long-random-preview-secret'
MAGICSSO_COOKIE_NAME = 'magic-sso'
Other supported settings:
MAGICSSO_AUTH_EVERYWHERE = False
MAGICSSO_COOKIE_DOMAIN = None
MAGICSSO_COOKIE_MAX_AGE = None
MAGICSSO_COOKIE_PATH = '/'
MAGICSSO_COOKIE_SAMESITE = 'Lax'
MAGICSSO_COOKIE_SECURE = True
MAGICSSO_DIRECT_USE = False
MAGICSSO_PUBLIC_ORIGIN = 'https://app.example.com'
MAGICSSO_PUBLIC_URLS = ['login']
MAGICSSO_REQUEST_TIMEOUT = 5
MAGICSSO_TRUST_PROXY = False
MAGICSSO_ALLOWED_ORIGINS = ['https://app.example.com']
| Setting | Required | Default | Notes |
|---|---|---|---|
MAGICSSO_ALLOWED_ORIGINS |
No | [] |
Optional allowlist of absolute origins accepted when deriving the current site origin dynamically, especially behind trusted proxies. |
MAGICSSO_AUTH_EVERYWHERE |
Yes | None | When True, unauthenticated requests to non-public routes redirect to login. |
MAGICSSO_COOKIE_DOMAIN |
No | None |
Optional cookie domain used when the Django app stores the returned JWT. |
MAGICSSO_COOKIE_MAX_AGE |
No | None |
Optional persistent cookie lifetime in seconds for the Django-managed auth cookie. Set it to match or stay below the server JWT expiration. |
MAGICSSO_COOKIE_NAME |
Yes | None | Required at app startup. Should match the server cookie name. |
MAGICSSO_COOKIE_PATH |
No | / |
Optional path scope for the Django-managed auth cookie. Narrowing it can make auth unavailable outside that subtree. |
MAGICSSO_COOKIE_SAMESITE |
No | Lax |
Explicit SameSite policy for the Django-managed auth cookie. Must be one of Lax, Strict, or None. |
MAGICSSO_COOKIE_SECURE |
No | True |
Controls the Secure flag on the Django-managed auth cookie. |
MAGICSSO_DIRECT_USE |
Yes | None | When True, the login view redirects straight to the SSO server instead of rendering the local form. |
MAGICSSO_JWT_SECRET |
Yes | None | Required at app startup. Must match the server JWT secret. |
MAGICSSO_PREVIEW_SECRET |
Yes | None | Required at app startup. Used by /sso/verify-email/ to preview the email token before exchange. Must match the server preview secret. |
MAGICSSO_PUBLIC_ORIGIN |
No | None |
Explicit origin used for site-bound JWT audience checks. Recommended unless you intentionally rely on trusted proxy headers. |
MAGICSSO_PUBLIC_URLS |
No | ['login'] |
Public Django URL names that bypass auth middleware. |
MAGICSSO_REQUEST_TIMEOUT |
No | 5 |
Timeout in seconds for requests from Django to the SSO server. |
MAGICSSO_SERVER_URL |
Yes | None | Required at app startup. Base URL of the SSO server and expected issuer for site-bound auth tokens. |
MAGICSSO_TRUST_PROXY |
No | False |
Only enable this with a reverse proxy that sanitizes forwarded headers. When enabled without MAGICSSO_PUBLIC_ORIGIN, configure MAGICSSO_ALLOWED_ORIGINS. |
The package validates MAGICSSO_JWT_SECRET, MAGICSSO_PREVIEW_SECRET,
MAGICSSO_SERVER_URL, MAGICSSO_COOKIE_NAME, MAGICSSO_COOKIE_SAMESITE,
MAGICSSO_COOKIE_PATH, and the proxy/origin trust settings during app startup
so configuration mistakes fail fast.
Auth tokens are site-bound. The middleware and built-in /sso/verify-email/
view verify the returned token against the current Django origin and the SSO
server issuer. Upgrading to this release invalidates older session cookies that
were issued without siteId/aud/iss, so users need to sign in again after
deployment.
Keep USE_X_FORWARDED_HOST = False unless Django is only reachable through a
trusted proxy that overwrites forwarded headers. If you do enable
USE_X_FORWARDED_HOST, set MAGICSSO_TRUST_PROXY = True and configure either
MAGICSSO_PUBLIC_ORIGIN or a strict MAGICSSO_ALLOWED_ORIGINS allowlist so
site-bound JWT audience checks stay anchored to trusted origins.
Basic integration
- Add
'magic_sso_django'toINSTALLED_APPS. - Add
'magic_sso_django.middleware.MagicSsoMiddleware'toMIDDLEWARE. - Include
path('sso/', include('magic_sso_django.urls'))inurls.py. - Configure the required
MAGICSSO_*settings.
Keep Django's CsrfViewMiddleware enabled and submit logout through a POST form
with {% csrf_token %}. The built-in /sso/logout/ view is POST-only.
Verified requests expose both request.magic_sso_user_email and
request.magic_sso_user_scope, and the decoded JWT payload now includes
siteId for site-bound authorization checks. The built-in /sso/login/ view
also accepts an optional scope query or form field and forwards it to the SSO
server.
Local development
uv sync --all-groups
uv run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file magic_link_sso_django-0.9.0.tar.gz.
File metadata
- Download URL: magic_link_sso_django-0.9.0.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79ba1c9b199fcfd9e55c74504d85e8ecad7b3d5fa5e8dde6577d7fbe576519df
|
|
| MD5 |
331e4eef822f89e2157bbc04d3c15f66
|
|
| BLAKE2b-256 |
53bfbca80d41b14af554dabf4dee9252e9bd4953bfd71d9d5cc0d4f37bbd7e25
|
Provenance
The following attestation bundles were made for magic_link_sso_django-0.9.0.tar.gz:
Publisher:
publish.yml on magic-link-sso/magic-sso
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
magic_link_sso_django-0.9.0.tar.gz -
Subject digest:
79ba1c9b199fcfd9e55c74504d85e8ecad7b3d5fa5e8dde6577d7fbe576519df - Sigstore transparency entry: 1391326472
- Sigstore integration time:
-
Permalink:
magic-link-sso/magic-sso@8a77e70f2e5de2b5fc065b519a31aae0808c3156 -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/magic-link-sso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8a77e70f2e5de2b5fc065b519a31aae0808c3156 -
Trigger Event:
push
-
Statement type:
File details
Details for the file magic_link_sso_django-0.9.0-py3-none-any.whl.
File metadata
- Download URL: magic_link_sso_django-0.9.0-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b823db90297c5bc93c6d5706c91d6fecea3e0b10c8f3fbc5dad14dab11eb8a03
|
|
| MD5 |
01f5eb5af06db4c3800700f1b6a56246
|
|
| BLAKE2b-256 |
065632cd251f331a3af61b71be91f56f5175513d33c7d3b384bba6bb35a29f3b
|
Provenance
The following attestation bundles were made for magic_link_sso_django-0.9.0-py3-none-any.whl:
Publisher:
publish.yml on magic-link-sso/magic-sso
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
magic_link_sso_django-0.9.0-py3-none-any.whl -
Subject digest:
b823db90297c5bc93c6d5706c91d6fecea3e0b10c8f3fbc5dad14dab11eb8a03 - Sigstore transparency entry: 1391326534
- Sigstore integration time:
-
Permalink:
magic-link-sso/magic-sso@8a77e70f2e5de2b5fc065b519a31aae0808c3156 -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/magic-link-sso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8a77e70f2e5de2b5fc065b519a31aae0808c3156 -
Trigger Event:
push
-
Statement type: