mozilla-django-oidc is a lightweight authentication and access management library for integrating Django applications with OpenID Connect enabled authentication services. It is actively maintained with frequent updates, currently at version 5.0.2, and typically releases new versions to support new Django and Python versions.
pip install mozilla-django-oidcVerified import paths — ran on the pinned version, not inferred.
This quickstart outlines the essential `settings.py` and `urls.py` configurations. You must add `mozilla_django_oidc` to `INSTALLED_APPS` and include its `OIDCAuthenticationBackend` in `AUTHENTICATION_BACKENDS`. Critical OIDC provider (OP) and relying party (RP) details (`OIDC_OP_*`, `OIDC_RP_CLIENT_ID`, `OIDC_RP_CLIENT_SECRET`) must be provided, ideally via environment variables for security. The library's URLs are included via `path('oidc/', include('mozilla_django_oidc.urls'))`. Basic login and logout links can then be added to your templates.
Review any custom JWT processing logic and update it to use `PyJWT` or `mozilla-django-oidc`'s updated internal mechanisms.
Ensure `LOGOUT_REDIRECT_URL` is explicitly set in your `settings.py` to the desired post-logout destination. If not set, it might cause an error or unexpected redirects.
Upgrade your Django installation to at least 4.2 and your Python version to at least 3.10 to be compatible with current versions of `mozilla-django-oidc`.
Always define all required `OIDC_OP_*` and `OIDC_RP_CLIENT_*` settings. It is highly recommended to fetch sensitive values like `OIDC_RP_CLIENT_SECRET` from environment variables, not hardcode them.
For custom username generation, set `OIDC_USERNAME_ALGO` to a Python dotted path to your custom function, or override `OIDCAuthenticationBackend.create_user` or `filter_users_by_claims` for more complex scenarios.