Skip to content

Commit c4fb895

Browse files
committed
Fixed OIDC authentication for SCIM endpoints
Previously, the Coldfront SCIM endpoints could not perform OIDC authentication, preventing usage of the client credentials and device authorization flows. A authentication middleware which subclasses from the one provided by `django_scim` has been added, which will perform OIDC authentication given an access token in the "Authorization" HTTP request header. The SCIM endpoint is now available to Coldfront users with "staff" or "superuser" status.
1 parent 2331171 commit c4fb895

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Diff for: src/coldfront_plugin_api/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
"GROUP_ADAPTER": "coldfront_plugin_api.scim_v2.adapter_group.SCIMColdfrontGroup",
1515
"GROUP_FILTER_PARSER": "coldfront_plugin_api.scim_v2.filters.ColdfrontGroupFilterQuery",
1616
"GET_IS_AUTHENTICATED_PREDICATE": "coldfront_plugin_api.utils.is_user_superuser",
17+
"AUTH_CHECK_MIDDLEWARE": "coldfront_plugin_api.scim_v2.auth_middleware.SCIMColdfrontAuthCheckMiddleware",
1718
}

Diff for: src/coldfront_plugin_api/scim_v2/auth_middleware.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import logging
2+
3+
from django_scim.middleware import SCIMAuthCheckMiddleware
4+
from mozilla_django_oidc.contrib.drf import OIDCAuthentication
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
class SCIMColdfrontAuthCheckMiddleware(SCIMAuthCheckMiddleware):
10+
def __call__(self, request, *args, **kwargs):
11+
response = None
12+
if hasattr(self, "process_request"):
13+
response = self.process_request(request)
14+
if not response:
15+
response = self.get_response(request, *args, **kwargs)
16+
if hasattr(self, "process_response"):
17+
response = self.process_response(request, response)
18+
return response
19+
20+
def process_request(self, request):
21+
oidc_auth_obj = OIDCAuthentication()
22+
user = oidc_auth_obj.authenticate(request)
23+
24+
if not user or not user[0].is_staff:
25+
return super().process_request(request)
26+
27+
def process_response(self, request, response):
28+
return response

Diff for: src/coldfront_plugin_api/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def is_user_superuser(user: User):
5959
As a temporary hack, this function will handle raising the appropriate 403 error if
6060
user is authenticated, but not superuser
6161
"""
62-
if user.is_authenticated and not user.is_superuser:
62+
if user.is_authenticated and not user.is_staff:
6363
raise PermissionDenied
6464
else:
6565
return user.is_authenticated

0 commit comments

Comments
 (0)