Skip to content

Commit c54ac1b

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. It will perform OIDC authentication if the `PLUGIN_AUTH_OIDC` env var is set to True.
1 parent 2331171 commit c54ac1b

File tree

3 files changed

+19
-1
lines changed

3 files changed

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

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
import logging
3+
4+
from django_scim.middleware import SCIMAuthCheckMiddleware
5+
from mozilla_django_oidc.contrib.drf import OIDCAuthentication
6+
7+
logger = logging.getLogger(__name__)
8+
9+
10+
class SCIMColdfrontAuthCheckMiddleware(SCIMAuthCheckMiddleware):
11+
def process_request(self, request):
12+
if not request.user or not request.user.is_staff:
13+
# PLUGIN_AUTH_OIDC implies DRF OIDC backend is configured
14+
if os.getenv("PLUGIN_AUTH_OIDC") == "True":
15+
oidc_auth_obj = OIDCAuthentication()
16+
request.user = oidc_auth_obj.authenticate(request)
17+
return super().process_request(request)

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)