A database-backed configuration for mozilla-django-oidc
Project description
1 Welcome to mozilla_django_oidc_db’s documentation!
- Version:
0.4.0
- Source:
- Keywords:
OIDC, django, database, authentication
- PythonVersion:
3.7
Database-backed settings for mozilla-django-oidc, with modified unique identifiers
2 Features
Thin layer on top of mozilla-django-oidc
Allows configuration of OpenID Connect variables via django-solo
Overrides mozilla-django-oidc default behaviour, using the sub claim instead of the email claim as unique identifier for users
mozilla-django-oidc-db provides a database singleton for several configuration variables required for mozilla-django-oidc, moving them from deploy-time to run-time. This enables modification of the configuration, without having to restart the application.
Additionally, mozilla-django-oidc-db by default uses the sub (subject) claim instead of the email claim as the unique identifier for users in the RP (Relying Party) application. Using email as the unique identifier is not recommended, as mentioned in the OpenID Connect specification.
3 Installation
3.1 Requirements
Python 3.7 or above
setuptools 30.4.0 or above
Django 2.2 or newer
PostgreSQL
3.2 Install
pip install mozilla-django-oidc-db
This will also install the following packages:
mozilla-django-oidc
django-solo
psycopg2
django-better-admin-arrayfield
3.3 Django settings
Make sure the following libraries are added to your INSTALLED_APPS:
INSTALLED_APPS = [
...
"django_better_admin_arrayfield",
"solo",
"mozilla_django_oidc",
"mozilla_django_oidc_db",
...
]
Add mozilla_django_oidc_db.backends.OIDCAuthenticationBackend to the AUTHENTICATION_BACKENDS, this backend replaces mozilla_django_oidc.auth.OIDCAuthenticationBackend:
AUTHENTICATION_BACKENDS = [
...
"mozilla_django_oidc_db.backends.OIDCAuthenticationBackend",
...
]
Ensure that LOGIN_REDIRECT_URL and LOGOUT_REDIRECT_URL are configured. For example:
LOGIN_REDIRECT_URL = reverse_lazy("admin:index")
LOGOUT_REDIRECT_URL = reverse_lazy("admin:index")
To enable validation of ID tokens by renewing them, add mozilla_django_oidc_db.middleware.SessionRefresh to the middleware, this middleware replaces mozilla_django_oidc.middleware.SessionRefresh:
MIDDLEWARE = [
# middleware involving session and authentication must come first
...
"mozilla_django_oidc_db.middleware.SessionRefresh",
...
]
Furthermore, ensure the following settings are configured:
OIDC_AUTHENTICATE_CLASS = "mozilla_django_oidc_db.views.OIDCAuthenticationRequestView"
MOZILLA_DJANGO_OIDC_DB_CACHE = "oidc"
MOZILLA_DJANGO_OIDC_DB_CACHE_TIMEOUT = 1
MOZILLA_DJANGO_OIDC_DB_CACHE is used to cache the configuration that is stored in the database, to prevent a lot of database lookups. Ensure this cache is configured in CACHES (using the backend of choice):
CACHES = {
"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"},
...
"oidc": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"},
}
Add the urlpatterns:
urlpatterns = [
...
path("oidc/", include("mozilla_django_oidc.urls")),
...
]
Add the login link to your templates:
{% get_solo 'mozilla_django_oidc_db.OpenIDConnectConfig' as oidc_config %}
{% if oidc_config.enabled %}
<div class="submit-row">
<a href="{% url 'oidc_authentication_init' %}">{% trans "Login with OIDC" %}</a>
</div>
{% endif %}
4 Usage
Now OpenID Connect can be enabled/disabled via the admin (disabled by default) and the following settings for OpenID Connect can be configured in the admin:
oidc_rp_client_id
oidc_rp_client_secret
oidc_rp_sign_algo
oidc_rp_scopes_list
oidc_op_discovery_endpoint
oidc_op_jwks_endpoint
oidc_op_authorization_endpoint
oidc_op_token_endpoint
oidc_op_user_endpoint
oidc_rp_idp_sign_key
If the oidc_op_discovery_endpoint is supplied, the other endpoints will be derived from this discovery endpoint.
In case no value is provided for one of these variables, the default from mozilla-django-oidc will be used (if there is one). A detailed description of all settings can be found in the mozilla-django-oidc settings documentation
For more detailed documentation, refer to the mozilla-django-oidc documentation. In this documentation the origin of the admin configurable settings is also explained.
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
File details
Details for the file mozilla-django-oidc-db-0.4.0.tar.gz
.
File metadata
- Download URL: mozilla-django-oidc-db-0.4.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6797ae6224eccd50ea3924e81a4570bff244e9f81f819b565d0f89621395986 |
|
MD5 | 548817219b4d1ae68516830ab6359b2e |
|
BLAKE2b-256 | 14706039b06af27e14cb55c29a5fd02c00c5b19d25b9e63ee8c31edf00ce50a1 |
File details
Details for the file mozilla_django_oidc_db-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: mozilla_django_oidc_db-0.4.0-py3-none-any.whl
- Upload date:
- Size: 21.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e633f5ef659be647557d1155b3217d751010c699052297e491fc5410291f8638 |
|
MD5 | aaa7b75bb2421486f673e0d2d99e43f6 |
|
BLAKE2b-256 | e864e6cf6006e050895a179cf92ba9ea90dda57a8415df8c32304d370fdbc704 |