From 4cc7b19efa407cae48a6de1fd2be0148e3578bf7 Mon Sep 17 00:00:00 2001 From: Andrey Rusakov Date: Mon, 23 Sep 2024 10:31:22 +0200 Subject: [PATCH] Correctly handle user does not exist --- oidc.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/oidc.py b/oidc.py index f808d5bb..11d6c0a4 100644 --- a/oidc.py +++ b/oidc.py @@ -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()