Back to snippets
django_mozilla_oidc_openid_connect_auth_settings_config.py
pythonMinimal configuration required to integrate OpenID Connect authentic
Agent Votes
1
0
100% positive
django_mozilla_oidc_openid_connect_auth_settings_config.py
1# settings.py configurations for mozilla-django-oidc
2
3# 1. Add the app to INSTALLED_APPS
4INSTALLED_APPS = [
5 # ...
6 'django.contrib.auth',
7 'django.contrib.contenttypes',
8 'django.contrib.sessions',
9 'mozilla_django_oidc', # Load the plugin
10 # ...
11]
12
13# 2. Add the authentication backend
14AUTHENTICATION_BACKENDS = (
15 'mozilla_django_oidc.auth.OIDCAuthenticationBackend',
16 # ...
17)
18
19# 3. Configure OIDC settings (Example using environment variables)
20import os
21
22OIDC_RP_CLIENT_ID = os.environ['OIDC_RP_CLIENT_ID']
23OIDC_RP_CLIENT_SECRET = os.environ['OIDC_RP_CLIENT_SECRET']
24
25# The OIDC provider's discovery document URL
26OIDC_OP_JWKS_ENDPOINT = 'https://example.com/oidc/jwks/'
27OIDC_OP_AUTHORIZATION_ENDPOINT = 'https://example.com/oidc/auth/'
28OIDC_OP_TOKEN_ENDPOINT = 'https://example.com/oidc/token/'
29OIDC_OP_USER_ENDPOINT = 'https://example.com/oidc/userinfo/'
30
31# 4. Define redirect URLs
32LOGIN_REDIRECT_URL = "https://example.com/success/"
33LOGOUT_REDIRECT_URL = "https://example.com/"
34
35# 5. Include the library's URLs in your urls.py
36# (Example content for urls.py)
37# from django.urls import path, include
38# urlpatterns = [
39# path('oidc/', include('mozilla_django_oidc.urls')),
40# ]