Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #68 from kpn/feature/initialize-request-bugfix
Browse files Browse the repository at this point in the history
FIX: initialize request earlier so we have access to scopes
  • Loading branch information
mjholtkamp authored Jan 8, 2020
2 parents 670e072 + b130882 commit 6640bd6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion katka/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ class UserOrScopeViewSet(GenericViewSet):
permission_classes = [IsGroupAuthenticated | HasFullScope]

def initialize_request(self, request, *args, **kwargs):
drf_request = super().initialize_request(request, *args, **kwargs)

auth_type = AuthType.ANONYMOUS
if getattr(request, "user", None) is not None and not request.user.is_anonymous:
auth_type = AuthType.GROUPS
elif getattr(request, "scopes", None) is not None:
auth_type = AuthType.SCOPES

# set it on the django HttpRequest
request.katka_auth_type = auth_type
return super().initialize_request(request, *args, **kwargs)

return drf_request

def get_queryset(self):
# do not call super().get_queryset() since it raises NotImplementedError
Expand Down

0 comments on commit 6640bd6

Please sign in to comment.