Skip to content

Commit b49c418

Browse files
authored
Gateway middleware only update if user is changing (#307)
1 parent 1da8b4a commit b49c418

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/apigateway/mitol/apigateway/backends.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def authenticate(self, request, remote_user):
3232
user = None
3333
username = self.clean_username(remote_user)
3434

35+
# if the current user and the user from the backend match
36+
# just return that user and do no further queries or configuration
37+
if getattr(request.user, self.lookup_field, None) == username:
38+
user = request.user
39+
return user if self.user_can_authenticate(user) else None
40+
3541
if self.create_unknown_user:
3642
user, created = User.objects.get_or_create(**{self.lookup_field: username})
3743
else:
@@ -48,6 +54,12 @@ async def aauthenticate(self, request, remote_user):
4854
user = None
4955
username = self.clean_username(remote_user)
5056

57+
# if the current user and the user from the backend match
58+
# just return that user and do no further queries or configuration
59+
if getattr(request.user, self.lookup_field, None) == username:
60+
user = request.user
61+
return user if self.user_can_authenticate(user) else None
62+
5163
if self.create_unknown_user:
5264
user, created = await User.objects.aget_or_create(
5365
**{self.lookup_field: username}

0 commit comments

Comments
 (0)