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 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