Terrance / SkPy

An unofficial Python library for interacting with the Skype HTTP API.
https://skpy.t.allofti.me
BSD 3-Clause "New" or "Revised" License
263 stars 66 forks source link

Login issues with pre-microsoft skype account linked to live account (?) + app password. #210

Closed truenicoco closed 2 years ago

truenicoco commented 2 years ago

Context: I am using your library for an XMPP gateway and it works (almost) great. My account was created a long time account, before skype was bought by microsoft, but is now linked to a microsoft account. Since I had trouble logging in, I set up an application password. To successfully login, I had to hack something like this:

        try:
            self.sk = await self.async_wrap(
                skpy.Skype,
                f["username"],
                f["password"],
                str(self.skype_token_path),
            )
        except skpy.core.SkypeApiException:
            # workaround for https://github.com/Terrance/SkPy/issues/164
            # not sure why, but I need this for my (nicoco's) account
            # FWIW, I have a live (I think) a account with a very old skype account (pre-microsoft)
            # and I set up 2FA + app password for slidge
            self.sk = await self.async_wrap(skpy.Skype)
            self.sk.conn.setTokenFile(str(self.skype_token_path))
            self.sk.conn.soapLogin(f["username"], f["password"])

which works and can send/receive messages (with some other asyncio/threading hacks that I think are not relevant here) for a few days.

After a while, I guess when the connection token has to be refreshed, I have this traceback:

Traceback (most recent call last):   
  File "/usr/local/lib/python3.9/threading.py", line 980, in _bootstrap_inner                                                                                                                                                                                   
self.run()
  File "/usr/local/lib/python3.9/threading.py", line 917, in run                                                                           
self._target(*self._args, **self._kwargs)
  File "/venv/lib/python3.9/site-packages/slidge/plugins/skype.py", line 117, in skype_blocking                                        
for event in self.sk.getEvents():                                                                                                      
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 76, in wrapper                                                           
return fn(self, *args, **kwargs)
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 76, in wrapper
return fn(self, *args, **kwargs)
  File "/venv/lib/python3.9/site-packages/skpy/main.py", line 111, in getEvents
for json in self.conn.endpoints["self"].getEvents():
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 1128, in getEvents
return self.conn("POST", "{0}/users/ME/endpoints/{1}/subscriptions/0/poll".format(self.conn.msgsHost, self.id),
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 214, in __call__
self.verifyToken(auth)
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 351, in verifyToken
self.getRegToken()
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 478, in getRegToken
self.verifyToken(self.Auth.SkypeToken)
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 348, in verifyToken
self.getSkypeToken()
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 188, in inner
return method(*args, **kwargs)
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 395, in liveLogin
self.tokens["skype"], self.tokenExpiry["skype"] = SkypeLiveAuthProvider(self).auth(user, pwd)
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 605, in auth
self.getT(user, pwd)
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 649, in getT
stage2Resp = self.check(self.conn("POST", "{0}/ppsecure/post.srf".format(SkypeConnection.API_MSACC),
  File "/venv/lib/python3.9/site-packages/skpy/conn.py", line 619, in check
raise SkypeApiException(errMsg, resp)
skpy.core
.
SkypeApiException
: 
("Your account or password is incorrect. If you don't remember your password, reset it now.", <Response [200]>)

I am thinking this is probably related to the login hack I had to use. I think I can work around this by just re-logging like I do when this happens, but was wondering if there was an easy, cleaner fix that comes to mind. The library is quite complex and I must confess I do not master all the different auth options.

Terrance commented 2 years ago

What format are you providing your username in? You appear to be forcing SOAP authentication at the start, but the automatic renewal is using the Live (legacy) auth, which does not support application passwords -- this is presumably because you're passing in a Skype username instead of your Microsoft account's email address, and providing the latter should both avoid needing to force it and handle the renewal correctly.

truenicoco commented 2 years ago

Oh I am indeed providing my Skype username. I don't even know what my associated live email is. Thanks for your reply, I'll investigate and report back when I have time to work on this again.

EDIT: Logging in with the email address seems to fix the issue. Thanks for your help, and the solution was to remove my ugly bogus workaround, which is nice.