Explorar o código

Handle UserInvalidCredentials responses

Tulir Asokan %!s(int64=2) %!d(string=hai) anos
pai
achega
94c109c2ce

+ 1 - 0
mauigpapi/errors/__init__.py

@@ -21,6 +21,7 @@ from .response import (
     IGInactiveUserError,
     IGLoginBadPasswordError,
     IGLoginError,
+    IGLoginInvalidCredentialsError,
     IGLoginInvalidUserError,
     IGLoginRequiredError,
     IGLoginTwoFactorRequiredError,

+ 4 - 0
mauigpapi/errors/response.py

@@ -152,6 +152,10 @@ class IGLoginInvalidUserError(IGLoginError):
     pass
 
 
+class IGLoginInvalidCredentialsError(IGLoginError):
+    pass
+
+
 class IGBad2FACodeError(IGResponseError):
     pass
 

+ 5 - 1
mauigpapi/http/base.py

@@ -18,7 +18,6 @@ from __future__ import annotations
 from typing import Any, Type, TypeVar
 import json
 import logging
-import random
 import time
 
 from aiohttp import ClientResponse, ClientSession, ContentTypeError, CookieJar
@@ -39,6 +38,7 @@ from ..errors import (
     IGFBSSODisabled,
     IGInactiveUserError,
     IGLoginBadPasswordError,
+    IGLoginInvalidCredentialsError,
     IGLoginInvalidUserError,
     IGLoginRequiredError,
     IGLoginTwoFactorRequiredError,
@@ -286,6 +286,10 @@ class BaseAndroidAPI:
         elif error_type == "rate_limit_error":
             raise IGRateLimitError(resp, data)
 
+        exception_name = data.get("exception_name")
+        if exception_name == "UserInvalidCredentials":
+            raise IGLoginInvalidCredentialsError(resp, data)
+
         raise IGResponseError(resp, data)
 
     def _handle_response_headers(self, resp: ClientResponse) -> None:

+ 3 - 0
mautrix_instagram/commands/auth.py

@@ -25,6 +25,7 @@ from mauigpapi.errors import (
     IGChallengeError,
     IGChallengeWrongCodeError,
     IGLoginBadPasswordError,
+    IGLoginInvalidCredentialsError,
     IGLoginInvalidUserError,
     IGLoginTwoFactorRequiredError,
 )
@@ -123,6 +124,8 @@ async def login(evt: CommandEvent) -> None:
         await evt.reply("Invalid username")
     except IGLoginBadPasswordError:
         await evt.reply("Incorrect password")
+    except IGLoginInvalidCredentialsError:
+        await evt.reply("Incorrect username or password")
     except Exception as e:
         evt.log.exception("Failed to log in")
         await evt.reply(f"Failed to log in: {e}")

+ 10 - 0
mautrix_instagram/web/provisioning_api.py

@@ -38,6 +38,7 @@ from mauigpapi.errors import (
     IGFBNoContactPointFoundError,
     IGFBSSODisabled,
     IGLoginBadPasswordError,
+    IGLoginInvalidCredentialsError,
     IGLoginInvalidUserError,
     IGLoginRequiredError,
     IGLoginTwoFactorRequiredError,
@@ -301,6 +302,15 @@ class ProvisioningAPI:
                 status=404,
                 headers=self._acao_headers,
             )
+        except IGLoginInvalidCredentialsError as e:
+            self.log.debug("%s tried to log in with invalid credentials %s", user.mxid, username)
+            self.log.debug("Login error body: %s", e.body.serialize())
+            track(user, "$login_failed", {"error": "invalid-credentials"})
+            return web.json_response(
+                data={"error": "Invalid username or password", "status": "invalid-credentials"},
+                status=403,
+                headers=self._acao_headers,
+            )
         except IGLoginBadPasswordError:
             self.log.debug("%s tried to log in as %s with the wrong password", user.mxid, username)
             track(user, "$login_failed", {"error": "incorrect-password"})