taylordotfish / harmony

A free/libre program for performing account-related tasks with Discord
GNU General Public License v3.0
86 stars 8 forks source link

Cannot log-in from account with 2FA enabled #20

Open Nardol opened 9 months ago

Nardol commented 9 months ago

When typing log-in, typing my e-mail then my password I have the following error:

Error encountered while running the command:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/harmony/harmony.py", line 257, in exec_single_command
    func()
  File "/usr/lib/python3/dist-packages/harmony/harmony.py", line 172, in result
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/harmony/harmony.py", line 391, in log_in
    response = self.try_with_captcha(
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/harmony/harmony.py", line 341, in try_with_captcha
    response = self.try_once_with_captcha(*args, ask=ask, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/harmony/harmony.py", line 321, in try_once_with_captcha
    response = self.try_request(lambda: func(None))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/harmony/harmony.py", line 272, in try_request
    return func()
           ^^^^^^
  File "/usr/lib/python3/dist-packages/harmony/harmony.py", line 321, in <lambda>
    response = self.try_request(lambda: func(None))
                                        ^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/harmony/harmony.py", line 392, in <lambda>
    "Login failed.", lambda key: self.dc.log_in(
                                 ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/harmony/discord.py", line 459, in log_in
    self.token = resp.token
                 ^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/harmony/discord.py", line 67, in token
    return self.json["token"]
           ~~~~~~~~~^^^^^^^^^
KeyError: 'token'

A friend who has not set any 2FA can log-in successfully.

I have the project to adopte the python3-harmony Debian package, which is fully not possible for now because of this error, if not able to log-in myself it is not possible to do anything else :slightly_frowning_face: I tried from a clean Python virtual environment with dependencies from deps/requirements.lock to be sure I only set tested dependencies.

Actual Debian package on Bookworm produce the same error.

pabs3 commented 9 months ago

I no longer have a Discord account but when I did, I didn't have that crash. It sounds like that harmony doesn't understand the data sent when 2FA is enabled for an account. So your options are to either disable 2FA or work on adding support for 2FA to harmony. You can probably start by printing the JSON just before the crash site and see from there what the code should be doing instead.

Nardol commented 9 months ago

In fact, it seams Harmony does not manage 2FA at all because token looks considered as present in all circumstances, I have not found the check before using it. Strange that nobody using 2fa has any crash when logging-in for the first time, or I am the only one to have tried and reported it.

Working on 2FA looks to have to be done from scratch, which is not really something I plan for now.

EDIT: and I am not sure about the decision of decreasing my account security :slightly_smiling_face:

But if someone wants to work on it, if there is no token there are also sms and/or mfa which can be set to true and ticket might be the data to use when requesting 2FA code from user. So other call to the API have to be done at this stage, which I have no real knowledge about.