From a568c04d572d1e7a8881944ecdad788f0c13ff6a Mon Sep 17 00:00:00 2001 From: Paul Florence Date: Mon, 17 Jun 2024 15:03:45 +0200 Subject: [PATCH 1/2] Add drf_spectacular schema generation --- django_pyoidc/drf/authentication.py | 3 ++- django_pyoidc/drf/schema.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 django_pyoidc/drf/schema.py diff --git a/django_pyoidc/drf/authentication.py b/django_pyoidc/drf/authentication.py index 6470166..c4ce017 100644 --- a/django_pyoidc/drf/authentication.py +++ b/django_pyoidc/drf/authentication.py @@ -24,7 +24,8 @@ def __init__(self, *args, **kwargs): self.client = OIDCClient(self.op_name) self.engine = OIDCEngine(self.op_name) - def extract_drf_opname(self): + @classmethod + def extract_drf_opname(cls): """ Given a list of opnames and setting in DJANGO_PYOIDC conf, extract the one having USED_BY_REST_FRAMEWORK=True. """ diff --git a/django_pyoidc/drf/schema.py b/django_pyoidc/drf/schema.py new file mode 100644 index 0000000..9687113 --- /dev/null +++ b/django_pyoidc/drf/schema.py @@ -0,0 +1,20 @@ +try: + from drf_spectacular.extensions import OpenApiAuthenticationExtension + + from django_pyoidc.utils import get_setting_for_sso_op + + class OIDCScheme(OpenApiAuthenticationExtension): + target_class = "django_pyoidc.drf.authentication.OIDCBearerAuthentication" + name = "openIdConnect" + match_subclasses = True + priority = -1 + + def get_security_definition(self, auto_schema): + from django_pyoidc.drf.authentication import OIDCBearerAuthentication + + op = OIDCBearerAuthentication.extract_drf_opname() + well_known_url = get_setting_for_sso_op(op, "OIDC_PROVIDER_DISCOVERY_URI") + return {"type": "openIdConnect", "openIdConnectUrl": well_known_url} + +except ImportError: + pass From d8056353a4677316ad20ac9d6b063299d4d376bb Mon Sep 17 00:00:00 2001 From: Paul Florence Date: Mon, 17 Jun 2024 15:16:14 +0200 Subject: [PATCH 2/2] Prepare release 0.0.8 --- django_pyoidc/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_pyoidc/VERSION b/django_pyoidc/VERSION index 5a5831a..d169b2f 100644 --- a/django_pyoidc/VERSION +++ b/django_pyoidc/VERSION @@ -1 +1 @@ -0.0.7 +0.0.8