Skip to content

Commit

Permalink
Merge pull request #8 from makinacorpus/drf_spectacular_support
Browse files Browse the repository at this point in the history
Add drf_spectacular schema generation
  • Loading branch information
gbip authored Jun 17, 2024
2 parents 59be625 + d805635 commit d7db7b1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django_pyoidc/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.7
0.0.8
3 changes: 2 additions & 1 deletion django_pyoidc/drf/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
20 changes: 20 additions & 0 deletions django_pyoidc/drf/schema.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d7db7b1

Please sign in to comment.