Skip to content

Commit f6f1f60

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 f6f1f60

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/coldfront_plugin_api/config.py

Lines changed: 1 addition & 0 deletions
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
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import logging
2+
3+
from django.http.response import HttpResponse
4+
from django.urls import reverse
5+
from django_scim.middleware import SCIMAuthCheckMiddleware
6+
from mozilla_django_oidc.contrib.drf import OIDCAuthentication
7+
8+
logger = logging.getLogger(__name__)
9+
10+
11+
class SCIMColdfrontAuthCheckMiddleware(SCIMAuthCheckMiddleware):
12+
def __call__(self, request, *args, **kwargs):
13+
response = None
14+
if hasattr(self, 'process_request'):
15+
response = self.process_request(request)
16+
if not response:
17+
response = self.get_response(request, *args, **kwargs)
18+
if hasattr(self, 'process_response'):
19+
response = self.process_response(request, response)
20+
return response
21+
22+
def process_request(self, request):
23+
oidc_auth_obj = OIDCAuthentication()
24+
user = oidc_auth_obj.authenticate(request)
25+
26+
if not user or not user[0].is_staff:
27+
return super().process_request(request)
28+
29+
def process_response(self, request, response):
30+
return response

src/coldfront_plugin_api/utils.py

Lines changed: 1 addition & 1 deletion
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)