From 7a1cd3132a64da92e738130d045a58125c9c17d5 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 20 Jul 2022 12:11:32 +0200 Subject: [PATCH] auth_oidc: remove app_settings (#67542) --- src/authentic2_auth_oidc/app_settings.py | 44 ------------------- .../migrations/0010_auto_20220413_1622.py | 8 ++-- src/authentic2_auth_oidc/views.py | 7 +-- 3 files changed, 5 insertions(+), 54 deletions(-) delete mode 100644 src/authentic2_auth_oidc/app_settings.py diff --git a/src/authentic2_auth_oidc/app_settings.py b/src/authentic2_auth_oidc/app_settings.py deleted file mode 100644 index 8b90eb43..00000000 --- a/src/authentic2_auth_oidc/app_settings.py +++ /dev/null @@ -1,44 +0,0 @@ -# authentic2 - versatile identity manager -# Copyright (C) 2010-2019 Entr'ouvert -# -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -import sys - - -class AppSettings: - '''Thanks django-allauth''' - - __SENTINEL = object() - - def __init__(self, prefix): - self.prefix = prefix - - def _setting(self, name, dflt=__SENTINEL): - from django.conf import settings - from django.core.exceptions import ImproperlyConfigured - - v = getattr(settings, self.prefix + name, dflt) - if v is self.__SENTINEL: - raise ImproperlyConfigured('Missing setting %r' % (self.prefix + name)) - return v - - @property - def ENABLE(self): - return self._setting('ENABLE', True) - - -app_settings = AppSettings('A2_AUTH_OIDC_') -app_settings.__name__ = __name__ -sys.modules[__name__] = app_settings diff --git a/src/authentic2_auth_oidc/migrations/0010_auto_20220413_1622.py b/src/authentic2_auth_oidc/migrations/0010_auto_20220413_1622.py index 1a72f60e..67308540 100644 --- a/src/authentic2_auth_oidc/migrations/0010_auto_20220413_1622.py +++ b/src/authentic2_auth_oidc/migrations/0010_auto_20220413_1622.py @@ -1,14 +1,12 @@ # Generated by Django 2.2.28 on 2022-04-13 14:22 +from django.conf import settings from django.db import migrations from django.utils.text import slugify -from authentic2 import app_settings as global_settings -from authentic2_auth_oidc import app_settings - def add_base_authenticators(apps, schema_editor): - kwargs_settings = getattr(global_settings, 'AUTH_FRONTENDS_KWARGS', {}) + kwargs_settings = getattr(settings, 'AUTH_FRONTENDS_KWARGS', {}) oidc_provider_settings = kwargs_settings.get('oidc', {}) show_condition = oidc_provider_settings.get('show_condition') or '' @@ -28,7 +26,7 @@ def add_base_authenticators(apps, schema_editor): name=provider.name, slug=provider.slug or slugify(provider.name), ou=provider.ou, - enabled=provider.show and app_settings.ENABLE, + enabled=provider.show and getattr(settings, 'A2_AUTH_OIDC_ENABLE', True), order=oidc_provider_settings.get('priority', 2), show_condition=show_condition_authenticator, ) diff --git a/src/authentic2_auth_oidc/views.py b/src/authentic2_auth_oidc/views.py index 41e12cf6..1dc6d3aa 100644 --- a/src/authentic2_auth_oidc/views.py +++ b/src/authentic2_auth_oidc/views.py @@ -29,11 +29,10 @@ from django.utils.translation import get_language from django.utils.translation import ugettext as _ from django.views.generic.base import View -from authentic2.decorators import setting_enabled from authentic2.utils import crypto from authentic2.utils.misc import authenticate, good_next_url, login, redirect -from . import app_settings, models +from . import models from .utils import get_provider, get_provider_by_issuer logger = logging.getLogger(__name__) @@ -43,7 +42,6 @@ def make_nonce(state): return hashlib.sha256(state.encode() + settings.SECRET_KEY.encode()).hexdigest() -@setting_enabled('ENABLE', settings=app_settings) def oidc_login(request, pk, next_url=None, *args, **kwargs): provider = get_provider(pk) scopes = set(provider.scopes.split()) | {'openid'} @@ -106,7 +104,6 @@ def oidc_login(request, pk, next_url=None, *args, **kwargs): return response -@setting_enabled('ENABLE', settings=app_settings) def login_initiate(request, *args, **kwargs): if 'iss' not in request.GET: return HttpResponseBadRequest('missing iss parameter', content_type='text/plain') @@ -348,4 +345,4 @@ class LoginCallback(View): return self.continue_to_next_url(request) -login_callback = setting_enabled('ENABLE', settings=app_settings)(LoginCallback.as_view()) +login_callback = LoginCallback.as_view() -- 2.30.2