forked from developer italia

This commit is contained in:
gabdevele
2026-06-17 17:46:59 +02:00 Unverified
commit 69e71ec601
43 changed files with 6026 additions and 0 deletions
@@ -0,0 +1,16 @@
"""
ASGI config for example project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'federation_authority.settings')
application = get_asgi_application()
@@ -0,0 +1,81 @@
"""
Django settings for example project.
Generated by 'django-admin startproject' using Django 4.0.2.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
from .settingslocal import * # noqa: F401
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'federation_authority.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'federation_authority.wsgi.application'
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
@@ -0,0 +1,106 @@
import aiohttp
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'visione-cie-authority-local-dev'
DEBUG = True
ADMIN_PATH = 'admin/'
APPEND_SLASH = False
OIDCFED_DEFAULT_TRUST_ANCHOR = "http://127.0.0.1:8000"
OIDCFED_TRUST_ANCHORS = [OIDCFED_DEFAULT_TRUST_ANCHOR]
OIDCFED_PROVIDER_PROFILE = "spid"
OIDCFED_PROVIDER_MAX_REFRESH = 10
OIDCFED_REQUIRED_TRUST_MARKS = []
OIDCFED_FEDERATION_TRUST_MARKS_PROFILES = {
"openid_relying_party__public": {},
"openid_relying_party__private": {},
}
HTTPC_PARAMS = {
"connection": {"ssl": True},
"session": {"timeout": aiohttp.ClientTimeout(total=4)},
}
LOGIN_REDIRECT_URL = "/oidc/rp/echo_attributes"
LOGOUT_REDIRECT_URL = "/oidc/rp/landing"
LOGIN_URL = "/oidc/rp/landing"
ALLOWED_HOSTS = ['*']
AUTH_USER_MODEL = 'spid_cie_oidc_accounts.User'
INSTALLED_APPS = [
'spid_cie_oidc.accounts',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"bootstrap_italia_template",
'spid_cie_oidc.entity',
'spid_cie_oidc.authority',
'spid_cie_oidc.onboarding',
'spid_cie_oidc.relying_party',
'spid_cie_oidc.relying_party_test',
'spid_cie_oidc.provider',
'djagger'
]
TEMPLATE_LOADERS = (
'django.template.loaders.eggs.Loader'
)
DJAGGER_DOCUMENT = {
"app_names": ['spid_cie_oidc'],
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
LANGUAGE_CODE = 'it-it'
TIME_ZONE = 'Europe/Rome'
USE_I18N = True
USE_L10N = True
USE_TZ = True
DATA_UPLOAD_MAX_NUMBER_FIELDS = 65000
ADMINS = [('Visione', '[email protected]')]
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'default': {
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
},
},
'handlers': {
'console': {
'formatter': 'default',
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': False,
},
'spid_cie_oidc': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False,
}
}
}
SESSION_COOKIE_NAME = 'visione_authority_sessionid'
CSRF_COOKIE_NAME = 'visione_authority_csrftoken'
@@ -0,0 +1,271 @@
import aiohttp
import os
import sys
import logging
from spid_cie_oidc import __version__
if len(sys.argv) > 1 and sys.argv[1] == 'test':
logging.disable(logging.CRITICAL)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
# CHANGE THIS VALUE
SECRET_KEY = 'lrx(fg&+2e=$l=y8$!£$%$/£%412345234534543--345234-dfdfgsdf-myg%r3z!yjm(lg*l%-z'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# the path corresponding the admin backend, default if not defined: admin/
# CHANGE THIS VALUE
ADMIN_PATH = 'admin/'
APPEND_SLASH = False
# required for onboarding checks and also for all the leafs
OIDCFED_DEFAULT_TRUST_ANCHOR = "http://127.0.0.1:8000"
OIDCFED_TRUST_ANCHORS = [OIDCFED_DEFAULT_TRUST_ANCHOR]
OIDCFED_PROVIDER_PROFILE = "spid"
OIDCFED_PROVIDER_MAX_REFRESH = 10 #used in SPID
# OIDCFED_PROVIDER_MAX_CONSENT_TIMEFRAME = 3600 #used in CIE (seconds)
# for RP only
OIDCFED_IDENTITY_PROVIDERS = {
"spid": {
"http://127.0.0.1:8000/oidc/op" : OIDCFED_DEFAULT_TRUST_ANCHOR,
},
"cie": {
"http://127.0.0.1:8002/oidc/op" : OIDCFED_DEFAULT_TRUST_ANCHOR,
}
}
OIDCFED_REQUIRED_TRUST_MARKS = []
OIDCFED_FEDERATION_TRUST_MARKS_PROFILES = {
"openid_relying_party__public": {},
"openid_relying_party__private": {},
}
HTTPC_PARAMS = {
"connection": {"ssl": True},
"session": {"timeout": aiohttp.ClientTimeout(total=4)},
}
LOGIN_REDIRECT_URL = "/oidc/rp/echo_attributes"
LOGOUT_REDIRECT_URL = "/oidc/rp/landing"
LOGIN_URL = "/oidc/rp/landing"
FEDERATION_DEFAULT_POLICY = {
"openid_relying_party": {
# TODO: to be customized for each entities, not somethinf to default!
# "client_id": {"value": "https://rp.example.it/spid"},
# "redirect_uris": {
# "subset_of": [
# "https://rp.example.it/spid/cb1",
# "https://rp.example.it/spid/cb2"
# ]
# },
# "organization_name": {"value": "Example RP organization name"},
# "logo_uri": {
# "one_of": [
# "https://rp.example.it/logo_small.jpg",
# "https://rp.example.it/logo_big.jpg"
# ],
# "default": "https://rp.example.it/logo_small.jpg"
# },
# "policy_uri": {
# "value": "https://rp.example.it/policy.html"
# },
# "tos_uri": {
# "value": "https://rp.example.it/tos.html"
# },
"grant_types": {
"subset_of": [
"authorization_code",
"refresh_token"
]
},
# TODO: to be customized for each actor
"constraints": {
# "naming_constraints": {
# "permitted": [
# "https://rp.example.it"
# ]
# },
# defines how many intermediaries are allowed to this trust anchor
"max_path_length": 1
},
},
# TODO: TBD
"openid_provider": {},
"federation_entity": {},
"oauth_resource": {}
}
ALLOWED_HOSTS = ['*']
AUTH_USER_MODEL = 'spid_cie_oidc_accounts.User'
INSTALLED_APPS = [
'spid_cie_oidc.accounts',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# 'prettyjson',
"bootstrap_italia_template",
'spid_cie_oidc.entity',
'spid_cie_oidc.authority',
'spid_cie_oidc.onboarding',
'spid_cie_oidc.relying_party',
'spid_cie_oidc.relying_party_test',
'spid_cie_oidc.provider',
'djagger'
]
TEMPLATE_LOADERS = (
'django.template.loaders.eggs.Loader'
)
DJAGGER_DOCUMENT = {
"info": dict(
title = "SPID/CIE OIDC OpenAPI 3.0 Documentation",
description = "OpenAPI 3.0 Document Description",
termsOfService = "",
contact = {
"email": "[email protected]",
"url": "https://github.com/italia/spid-cie-oidc-django",
"name" : "Developers Italia"
},
license = {
"name": "CC BY 4.0",
"url": "https://creativecommons.org/licenses/by/4.0/"
},
version = __version__,
x_logo = {
"name": "Developers italia",
"url": "https://developers.italia.it/assets/icons/logo-it.svg"
}
),
"url_names": [
# Federation Authority
'oidcfed_fetch',
'oidcfed_resolve',
'oidcfed_list',
'oidcfed_trust_mark_status',
'oidcfed_advanced_entity_listing',
# Provider
'oidc_provider_authnrequest',
'oidc_provider_token_endpoint',
'oidc_provider_userinfo_endpoint',
'introspection_endpoint',
'oidc_provider_revoke_session',
# Relying Party
'spid_cie_rp_begin',
'spid_cie_rp_callback',
'spid_cie_rpinitiated_logout'
]
}
DATABASES = {
# if you need more power
# 'default': {
# 'ENGINE': 'django.db.backends.mysql',
# 'NAME': 'that-username',
# 'HOST': 'localhost',
# 'USER': 'that-user',
# 'PASSWORD': 'that-password',
# 'PORT': '',
# 'OPTIONS': {'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"}
# },
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'it-it'
TIME_ZONE = 'Europe/Rome'
USE_I18N = True
USE_L10N = True
USE_TZ = True
DATA_UPLOAD_MAX_NUMBER_FIELDS = 65000
# email notification on errors
# DEFAULT_FROM_EMAIL = 'fedauth-noreply@DOMAIN'
# SERVER_EMAIL = DEFAULT_FROM_EMAIL
# EMAIL_HOST = 'smtpservice.yourdomain.it'
# EMAIL_HOST_USER = '[email protected]'
# EMAIL_HOST_PASSWORD = 'mypassword'
# EMAIL_PORT = 587
# EMAIL_USE_TLS = True
ADMINS = [('name surname', 'user1@DOMAIN'),
('name surnale', 'user2@DOMAIN'),]
# LOGGING
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'default': {
# exact format is not important, this is the minimum information
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
},
'detailed': {
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s [%(pathname)s %(funcName)s:%(lineno)s]'
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'formatter': 'detailed',
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'console': {
'formatter': 'default',
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
"daily": {
"class": "logging.handlers.TimedRotatingFileHandler",
"level": "INFO",
"formatter": "default",
"filename": f"{BASE_DIR}/logs/trust_anchor.log",
"when": "midnight",
"backupCount": 96
}
},
'loggers': {
'django': {
'handlers': ['console', 'mail_admins'],
'level': 'ERROR',
'propagate': False,
},
'spid_cie_oidc': {
'handlers': ['console', 'mail_admins', "daily"],
'level': 'INFO',
'propagate': False,
}
}
}
@@ -0,0 +1,99 @@
"""acsia_agent_proj URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.contrib import admin
from django.urls import include, path, re_path
from django.views.static import serve
from spid_cie_oidc.entity.urls import urlpatterns as entity_urlpatterns
from spid_cie_oidc.authority.urls import urlpatterns as ta_urlpatterns
from spid_cie_oidc.onboarding.urls import urlpatterns as onb_urlpatterns
from spid_cie_oidc.provider.urls import urlpatterns as prov_urlpatterns
admin.site.site_header = "OIDC Federation Entity Administration"
admin.site.site_title = "OIDC Federation"
admin.site.index_title = "Welcome to OIDC Federation Entity Admin backend"
ADMIN_PATH = getattr(settings, 'ADMIN_PATH', 'admin/')
urlpatterns = []
urlpatterns.extend(entity_urlpatterns)
urlpatterns.extend(prov_urlpatterns)
urlpatterns.extend(ta_urlpatterns)
urlpatterns.extend(onb_urlpatterns)
urlpatterns.extend(
(
path(f"{ADMIN_PATH}", admin.site.urls),
re_path('^static/(?P<path>.*)$',
serve, {
'document_root': settings.STATIC_ROOT,
# 'show_indexes': True
}
),
)
)
if 'spid_cie_oidc.relying_party' in settings.INSTALLED_APPS:
from spid_cie_oidc.relying_party.urls import urlpatterns as rp_urlpatterns
urlpatterns.extend(rp_urlpatterns)
from spid_cie_oidc.entity.views import entity_configuration, resolve_entity_statement
urlpatterns.extend(
[
path(
f"oidc/rp/.well-known/openid-federation",
entity_configuration,
name="rp_entity_configuration",
),
path(
"oidc/rp/resolve",
resolve_entity_statement,
name="rp_entity_resolve",
),
]
)
if 'spid_cie_oidc.provider' in settings.INSTALLED_APPS:
from spid_cie_oidc.provider.urls import urlpatterns as op_urlpatterns
urlpatterns.extend(op_urlpatterns)
from spid_cie_oidc.entity.views import entity_configuration
urlpatterns.extend(
[
path(
f"oidc/op/.well-known/openid-federation",
entity_configuration,
name="op_entity_configuration",
),
path(
"oidc/op/resolve",
resolve_entity_statement,
name="op_entity_resolve",
),
]
)
if 'spid_cie_oidc.relying_party_test' in settings.INSTALLED_APPS:
from spid_cie_oidc.relying_party_test.urls import urlpatterns as rp_urlpatterns_test
urlpatterns.extend(rp_urlpatterns_test)
if 'djagger' in settings.INSTALLED_APPS:
urlpatterns.append(path('rest/', include('djagger.urls')))
@@ -0,0 +1,16 @@
"""
WSGI config for example project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'federation_authority.settings')
application = get_wsgi_application()