From a58210a4f8f693320c2136f2eb6dc0accc9d7e1e Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Mon, 12 Aug 2024 16:29:55 +0100 Subject: [PATCH] anonymous logs --- apps/authentication/backends.py | 5 +++-- apps/authentication/managers.py | 8 ++------ apps/authentication/views.py | 18 +++++++++--------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/apps/authentication/backends.py b/apps/authentication/backends.py index 75c45d4..88e6fa9 100644 --- a/apps/authentication/backends.py +++ b/apps/authentication/backends.py @@ -42,10 +42,11 @@ class DiscordAuthenticationBackend(BaseBackend): # also check the new `token_expires` field to see if the token is invalid # then request a new token, instead of making the user login again # + # UPDATE: + # is this even possible or necessary with the scope of this app? + # # https://discord.com/developers/docs/game-sdk/applications#data-models - log.debug(discord_user_data) - discord_user_id = discord_user_data["id"] existing_user = self.get_user(discord_user_id) log.debug("authenticating, does user exist: %s", bool(existing_user)) diff --git a/apps/authentication/managers.py b/apps/authentication/managers.py index a2ed367..cf0b7ae 100644 --- a/apps/authentication/managers.py +++ b/apps/authentication/managers.py @@ -27,14 +27,11 @@ class DiscordUserOAuth2Manager(BaseUserManager): The newly created DiscordUser instance. """ - username = discord_user_data.get("username") - log.debug("creating new user: %s", username) + log.info("creating new user") discord_user_data.update(extra_fields) user = discord_user_data # shorthand - log.debug(user) - return self.create( id=user["id"], username=user["username"], @@ -55,8 +52,7 @@ class DiscordUserOAuth2Manager(BaseUserManager): Create a user from their discord data, but also make them a superuser. """ - username = discord_user_data.get("username") - log.debug("creating new superuser: %s", username) + log.info("creating new superuser") extra_fields.setdefault("is_staff", True) extra_fields.setdefault("is_superuser", True) diff --git a/apps/authentication/views.py b/apps/authentication/views.py index 2a8d7bc..2b6a928 100644 --- a/apps/authentication/views.py +++ b/apps/authentication/views.py @@ -57,11 +57,11 @@ class DiscordLoginRedirect(View): A call is made to the Discord API. """ + log.debug("exchanging code for access token") + request_data = settings.DISCORD_CODE_EXCHANGE_REQUEST request_data["data"]["code"] = code - log.debug("request data: %s", request_data) - # Fetch the access token response = requests.post( url=f"{settings.DISCORD_API_URL}/oauth2/token", @@ -78,11 +78,11 @@ class DiscordLoginRedirect(View): token. """ + log.debug("refreshing access token") + request_data = settings.DISCORD_REFRESH_TOKEN_REQUEST request_data["data"]["refresh_token"] = refresh_token - log.debug("request data: %s", request_data) - response = requests.post( url=f"{settings.DISCORD_API_URL}/oauth2/token", data=request_data["data"], @@ -97,14 +97,16 @@ class DiscordLoginRedirect(View): A call is made to the Discord API. """ + log.debug("fetching raw user data") + response = requests.get( url=f"{settings.DISCORD_API_URL}/users/@me", headers={"Authorization": f"Bearer {access_token}"} ) - log.debug(response) data = response.json() + # Assign the default avatar if not data.get("avatar"): data["avatar"] = int(data["id"]) % 5 @@ -129,7 +131,7 @@ class GuildsView(View): status = response.status_code if status != 200: - log.debug("Bad status code getting guilds: %s", status) + log.warning("Bad status code getting guilds: %s", status) return JsonResponse(content, safe=False, status=status) valid_guilds = [guild for guild in response.json() if self._has_permissions(guild)] @@ -147,11 +149,9 @@ class GuildsView(View): class GuildChannelsView(View): def get(self, request, *args, **kwargs): + log.debug("fetching channels from guid") guild_id = request.GET.get("guild") - - log.debug("fetching channels from %s using token: %s", guild_id, settings.BOT_TOKEN) - response = requests.get( url=f"{settings.DISCORD_API_URL}/guilds/{guild_id}/channels", headers={"Authorization": f"Bot {settings.BOT_TOKEN}"}