Skip to content

Commit

Permalink
Correctly handle user does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Rusakov committed Sep 26, 2024
1 parent 73db81a commit 4cc7b19
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ def post(self, request):
# TODO: Test missing id token
# TODO: Localize error response
# TODO: Test same token multiple times
# TODO: Test user does not exist
# TODO: Test user exists, but unauthrized
# TODO: Test user exists and authorized
token_data = json.loads(request.body.decode("utf-8"))
if "token" not in token_data:
return JsonResponse({"error": "No token provided"}, status=400)

user_data = self._resolve_user_data(token_data["token"])
user = UserModel.objects.get(username=user_data["email"])
if not user:
try:
user = UserModel.objects.get(username=user_data["email"])
except UserModel.DoesNotExist:
user = UserModel.objects.create_user(username=user_data["email"])
_updateUser(user, user_data)
user.save()
Expand Down

0 comments on commit 4cc7b19

Please sign in to comment.