Skip to content

Commit

Permalink
scim: Use setattr to set request.user as scim_client.
Browse files Browse the repository at this point in the history
This is a type-unsafe workaround before we can fix the problem that
django_scim2 relies on request.user being present to authenticate
requests.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
  • Loading branch information
PIG208 authored and andersk committed Sep 26, 2022
1 parent ca2a4cb commit c9d7822
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion zerver/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,5 +786,7 @@ def process_request(self, request: HttpRequest) -> Optional[HttpResponse]:
# so we can assign the corresponding SCIMClient object to request.user - which
# will allow this request to pass request.user.is_authenticated checks from now on,
# to be served by the relevant views implemented in django-scim2.
request.user = scim_client
# Since request.user must be a UserProfile or AnonymousUser, setattr is a type-unsafe
# workaround to make this monkey-patching work.
setattr(request, "user", scim_client)
return None

0 comments on commit c9d7822

Please sign in to comment.