second phase of the project management dashboard

This commit is contained in:
Joren de Graaf
2026-10-13 20:37:56 +02:00
parent 3559b367e6
commit e4419b4a18
27 changed files with 1317 additions and 63 deletions
+49
View File
@@ -1,9 +1,12 @@
import os
from pathlib import Path
from django.core.exceptions import ImproperlyConfigured
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'django-insecure-local-development-only')
DEBUG = os.environ.get('DJANGO_DEBUG', '1') == '1'
if not DEBUG and (SECRET_KEY.startswith('django-insecure-') or len(SECRET_KEY) < 50):
raise ImproperlyConfigured('Set a strong DJANGO_SECRET_KEY when DJANGO_DEBUG=0.')
ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',')
INSTALLED_APPS = [
'django.contrib.admin', 'django.contrib.auth', 'django.contrib.sessions', 'django.contrib.messages',
@@ -11,6 +14,7 @@ INSTALLED_APPS = [
"django.contrib.staticfiles",
"core",
'projects',
'oauth2_provider',
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
@@ -19,6 +23,7 @@ MIDDLEWARE = [
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = "config.urls"
TEMPLATES = [{
@@ -39,3 +44,47 @@ LOGOUT_REDIRECT_URL = 'login'
CSRF_COOKIE_SECURE = not DEBUG
SESSION_COOKIE_SECURE = not DEBUG
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = not DEBUG
SECURE_HSTS_SECONDS = 31536000 if not DEBUG else 0
CSRF_TRUSTED_ORIGINS = [item for item in os.environ.get('DJANGO_CSRF_TRUSTED_ORIGINS', '').split(',') if item]
MCP_PUBLIC_URL = os.environ.get('MCP_PUBLIC_URL', 'http://127.0.0.1:8766/mcp')
OAUTH_ISSUER_URL = os.environ.get('OAUTH_ISSUER_URL', 'http://127.0.0.1:8765/')
if not DEBUG and (not MCP_PUBLIC_URL.startswith('https://') or not OAUTH_ISSUER_URL.startswith('https://')):
raise ImproperlyConfigured('MCP_PUBLIC_URL and OAUTH_ISSUER_URL must use HTTPS in production.')
OAUTH2_PROVIDER = {
'SCOPES': {'projects:read': 'Read projects and cards', 'projects:write': 'Create and edit projects and cards'},
'DEFAULT_SCOPES': ['projects:read'],
'ALLOWED_REDIRECT_URI_SCHEMES': ['http', 'https'] if DEBUG else ['https'],
'PKCE_REQUIRED': True,
'COMPLIANT_BCP_RFC9700_PKCE_METHOD': True,
'COMPLIANT_BCP_RFC9700_ACCESS_TOKEN_TRANSPORT': True,
'COMPLIANT_BCP_RFC9700_TOKEN_STORAGE': True,
'ACCESS_TOKEN_EXPIRE_SECONDS': 3600,
'REFRESH_TOKEN_REUSE_PROTECTION': True,
'DCR_ENABLED': True,
'DCR_REGISTRATION_PERMISSION_CLASSES': ['oauth2_provider.dcr.IsAuthenticatedDCRPermission'],
'COMPLIANT_BCP_RFC9700_IMPLICIT_GRANT': True,
'COMPLIANT_BCP_RFC9700_PASSWORD_GRANT': True,
'COMPLIANT_BCP_RFC9700_AUTHZ_RESPONSE_ISS': True,
}
OIDC_KEYS = ('OIDC_OP_ISSUER', 'OIDC_OP_AUTHORIZATION_ENDPOINT', 'OIDC_OP_TOKEN_ENDPOINT',
'OIDC_OP_USER_ENDPOINT', 'OIDC_OP_JWKS_ENDPOINT', 'OIDC_RP_CLIENT_ID', 'OIDC_RP_CLIENT_SECRET')
OIDC_ENABLED = all(os.environ.get(key) for key in OIDC_KEYS)
if any(os.environ.get(key) for key in OIDC_KEYS) and not OIDC_ENABLED:
raise ImproperlyConfigured('Set every OIDC provider variable, or leave all of them unset.')
if OIDC_ENABLED:
if not DEBUG and any(not os.environ[key].startswith('https://') for key in OIDC_KEYS[:5]):
raise ImproperlyConfigured('OIDC provider URLs must use HTTPS in production.')
INSTALLED_APPS.append('mozilla_django_oidc')
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend', 'projects.oidc.IdentityBackend']
OIDC_OP_ISSUER = os.environ['OIDC_OP_ISSUER']
OIDC_OP_AUTHORIZATION_ENDPOINT = os.environ['OIDC_OP_AUTHORIZATION_ENDPOINT']
OIDC_OP_TOKEN_ENDPOINT = os.environ['OIDC_OP_TOKEN_ENDPOINT']
OIDC_OP_USER_ENDPOINT = os.environ['OIDC_OP_USER_ENDPOINT']
OIDC_OP_JWKS_ENDPOINT = os.environ['OIDC_OP_JWKS_ENDPOINT']
OIDC_RP_CLIENT_ID = os.environ['OIDC_RP_CLIENT_ID']
OIDC_RP_CLIENT_SECRET = os.environ['OIDC_RP_CLIENT_SECRET']
OIDC_RP_SIGN_ALGO = 'RS256'
OIDC_RP_SCOPES = 'openid email profile'
OIDC_STORE_ACCESS_TOKEN = False
OIDC_STORE_ID_TOKEN = False
+8 -1
View File
@@ -1,11 +1,16 @@
from django.urls import path, include
from django.contrib.auth import views as auth_views
from django.contrib import admin
from django.conf import settings
from oauth2_provider.urls import metadata_urlpatterns
from core import views
from projects import views as project_views
urlpatterns = [
*metadata_urlpatterns,
path('o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
path('admin/', admin.site.urls),
path('accounts/login/', auth_views.LoginView.as_view(template_name='projects/login.html'), name='login'),
path('accounts/login/', project_views.ThrottledLoginView.as_view(), name='login'),
path('accounts/logout/', auth_views.LogoutView.as_view(), name='logout'),
path('accounts/password/change/', auth_views.PasswordChangeView.as_view(template_name='projects/form.html', success_url='/projects/profile/'), name='password_change'),
path('projects/', include('projects.urls')),
@@ -15,3 +20,5 @@ urlpatterns = [
path("home/", views.home, name="home"),
path("showcase/", views.showcase, name="showcase"),
]
if settings.OIDC_ENABLED:
urlpatterns.insert(0, path('oidc/', include('mozilla_django_oidc.urls')))