This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Re-auth fails after Token became invalid (Using Skype-credentials) #45
Copy link
Copy link
Open
Labels
Description
After 1 day the reauth after the token became invalid failed.
The credentials should still be present as it wasn't restarted
Running While: 2017-02-21 20:22:00.228576 (Skypetoken valid for 0:00:07.771455)
Error: Error Polling Messages : ("Couldn't retrieve PPFT from login form", <Response [200]>)
Traceback (most recent call last):
File "SkypeBot.py", line 290, in <function>
events = sk.getEvents()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 77, in wrapper
return fn(self, *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 77, in wrapper
return fn(self, *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/skpy/main.py", line 116, in getEvents
for json in self.conn.endpoints["self"].getEvents():
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 904, in getEvents
auth=SkypeConnection.Auth.RegToken).json().get("eventMessages", [])
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 193, in __call__
self.verifyToken(auth)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 337, in verifyToken
self.getRegToken()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 421, in getRegToken
endpoint.config()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 864, in config
"version": "908/1.30.0.128"}})
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 193, in __call__
self.verifyToken(auth)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 337, in verifyToken
self.getRegToken()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 421, in getRegToken
endpoint.config()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 864, in config
"version": "908/1.30.0.128"}})
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 193, in __call__
self.verifyToken(auth)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 337, in verifyToken
self.getRegToken()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 421, in getRegToken
endpoint.config()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 864, in config
"version": "908/1.30.0.128"}})
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 193, in __call__
self.verifyToken(auth)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 337, in verifyToken
self.getRegToken()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 421, in getRegToken
endpoint.config()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 864, in config
"version": "908/1.30.0.128"}})
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 193, in __call__
self.verifyToken(auth)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 337, in verifyToken
self.getRegToken()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 421, in getRegToken
endpoint.config()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 864, in config
"version": "908/1.30.0.128"}})
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 193, in __call__
self.verifyToken(auth)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 337, in verifyToken
self.getRegToken()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 421, in getRegToken
endpoint.config()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 864, in config
"version": "908/1.30.0.128"}})
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 193, in __call__
self.verifyToken(auth)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 337, in verifyToken
self.getRegToken()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 421, in getRegToken
endpoint.config()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 864, in config
"version": "908/1.30.0.128"}})
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 193, in __call__
self.verifyToken(auth)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 337, in verifyToken
self.getRegToken()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 415, in getRegToken
self.verifyToken(self.Auth.SkypeToken)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 334, in verifyToken
self.getSkypeToken()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 262, in getSkypeToken
self.liveLogin(user, pwd)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 359, in liveLogin
self.tokens["skype"], self.tokenExpiry["skype"] = SkypeLiveAuthProvider(self).auth(user, pwd)
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 532, in auth
params = self.getParams()
File "/usr/local/lib/python3.4/dist-packages/skpy/conn.py", line 543, in getParams
raise SkypeApiException("Couldn't retrieve PPFT from login form", loginResp)
skpy.core.SkypeApiException: ("Couldn't retrieve PPFT from login form", <Response [200]>)
subsequential calls failed with the same Error although not as many verifyToken-Recursions
Reactions are currently unavailable
Activity
Terrance commentedon Feb 22, 2017
When you provide a username/password, the
getSkypeToken()stub is replaced with a wrapper that uses the credentials, so you should be able to call that and reconnect.I'm not sure what's going on here though.
endpoint.config()requires a registration token, so it starts the reg-token handshake, but when it gets round to configuring the endpoint, it never actually got a new token? The eventual"Couldn't retrieve PPFT from login form"is most likely due to rate limiting if you're continuously calling the registration endpoint.You're getting spun in a loop because this check is failing -- perhaps you could try fetching a registration token manually, and comparing the previous token and expiry to what the API gives you?
DerGenaue commentedon Feb 22, 2017
The thing is that the LiveLogin (the replaced stub) is called in the end and subsequently fails.
What do the different tokens actually do?
DerGenaue commentedon Feb 22, 2017
Oh, I get it´; It thinks, the token is still valid which is why verifyToken passes in getRegToken and it proceeds to call config.
This is what the error looks like on later occasions:
Terrance commentedon Feb 22, 2017
There are two types of tokens -- Skype token, and registration token. The latter requires a former as part of the request, and both have their own expiries. Different APIs require different tokens. The presence and messaging endpoints (
client-s.gateway.messenger.live.com) take a registration token, most other APIs use the Skype token.verifyToken()tests a token exists and hasn't expired yet, and re-auths on failure. ButgetRegToken()shouldn't be called in the first place if the token's still valid. 🤔As noted above, probably down to rate limiting. If you try to sign in to Skype for Web from the same device, you may end up at a captcha/two-factor page.
If you set
SKPY_DEBUG_HTTP=1in your environment, you'll see the actual HTTP requests going on in the background. What's the server response just before you hit that error?Please also try the snippet and comparison as suggested previously.
Terrance commentedon Mar 4, 2017
@DerGenaue Any updates?
(P.S. I've pushed an update that includes headers in the HTTP debug output, please pull before testing.)
DerGenaue commentedon Mar 4, 2017
Not yet, had a stressful week but I think I can test it today
DerGenaue commentedon Mar 4, 2017
Result of resfreshSkypeToken:
And with a fresh Skype login (direct after Password input) this is the result of getSkypeToken():
DerGenaue commentedon Mar 5, 2017
does this help you?
Terrance commentedon Mar 6, 2017
First one renders as the username-only login form, but with no useful hidden tokens as far as I can tell. I guess that means the refresh token is invalid.
There's an admittedly rather hidden disclaimer on the refresh token provider, which ought to be copied to the
refreshSkypeToken()docstring:That is, Microsoft account logins (email or phone number as username) aren't supported by the upstream API. Does that apply to you?
Failing that, if you're trying to refresh after the Skype token expires, maybe that's too late and the refresh token expires then too... can you refresh at all before the expiry?
Second one, it's looking for a
PPFTfield but actually getting thetfield (which is usually the next step, after providing credentials). Maybe the browser session allows us to reauthenticate without credentials now? Should be fairly straightforward to check what's in the response and act accordingly.DerGenaue commentedon Mar 6, 2017
No Microsoft login, I read that disclaimer;
(Tried to find out the issue in the code by myself)
Just a plain Skype username.
Please note that I censored the tokens I found in the response with **
How did you find out about how to implement the RefreshTokenProvider?
Is it used by the Skype Web App?
Maybe we can look whether the protocol changed.
I did that refresh up there a few min after logging in
Terrance commentedon Mar 6, 2017
Just tested myself, the token renewal appears to work regardless of age.
Unsure if it works after expiry, I've got an open shell to check tomorrow.Edit: it works, but that's still not the issue here.Found a mention of the endpoint over here -- haven't seen it used anywhere in Skype for Web though.
DerGenaue commentedon Mar 9, 2017
So the refreshToken function works just fine for you?
That's really weird, you also use a normal skype login, right?
Terrance commentedon Mar 9, 2017
Yep, Skype username auth here, all seems to work. Reproducing bugs here is a right pain, things just seem to be broken for a minority of people. 🙁
lassic commentedon Mar 12, 2017
@OllieTerrance I've also been getting some errors sometimes around refreshing the token/login.
What's the recommended workflow for keeping a session active over days?
Right now, I'm doing
Skype(user, pwd, token_file)constructor for first login.Every 12 hrs I'm checking token expiry and trying to renew with:
setUserPwd(user, pwd)+getSkypeToken()(I'm only using the contacts.search API so far).Is this the correct approach? Should I be using
refreshSkypeTokenperiodically until I get an exception and only thengetSkypeToken?Terrance commentedon Mar 12, 2017
You can use
verifyToken(SkypeConnection.Auth.SkypeToken)to do a token refresh if expired (though currently this doesn't use the refresh flow, so requires username/password present in this session).There's also a handler to get a new registration tokens on API call failure, maybe this needs extending to refresh or get Skype tokens too...
3 remaining items
lassic commentedon Mar 13, 2017
so far no matter what I'm trying the account seems to get blocked when trying to relogin after 24hrs (token expiry). If I find anything else I'll update.
Terrance commentedon Mar 13, 2017
Blocked how? I've toyed with my test accounts, seems like I can reauthenticate via refreshing a Skype token (if a Skype username rather than Microsoft account), or getting a new one, both before and after expiry...
lassic commentedon Mar 14, 2017
Blocked meaning - trying to
verifyToken(SkypeConnection.Auth.SkypeToken)orrefreshSkypeToken()orgetSkypeToken()orSkype(...)after 24hrs (token expiry time) doesn't work for me. I always get the page that says the account is blocked and requires SMS verification.@OllieTerrance if you have a proposed chat medium we can take this discussion offline and I can try to supply more details.
lassic commentedon Mar 15, 2017
It's possible that deleting an existing token file prior to expiration (say after 22hrs), and then creating a new Skype(user, pwd, tokenFile) succeeds in keeping that user logged in without getting blocked.
I will update if that holds.
Terrance commentedon Mar 15, 2017
Curious. If you're doing multiple searches, I wonder if they're flagging you for it...
I'm (somewhat, at the moment) around on Hangouts or via email (
githubat this domain) if you want to poke some more out of band.lassic commentedon Mar 15, 2017
Could very well be flagged on multiple searches. We'll see how it goes in the upcoming days. Thanks for the chat options, I may reach out if I get some more details. Also for the code and all the help here.
Terrance commentedon May 17, 2017
This issue has been hanging around a bit, but I haven't got a clear solution.
The current implementation will request a new Skype token (via
verifyToken(auth)) when the current one expires, assuming you provided your password when connecting. This means token-only logins won't refresh, which does kinda defeat the point of them. The cleanest solution, I think, would be to use the refresh provider when available, else (probablytry...except) fall back to reauthenticating.codeofdusk commentedon Jun 22, 2018
This may be an unrelated issue, but SkypeEventLoop throws an exception after 24 hours. Could a check be added to refresh the auth token before it expires for users of that class?
Terrance commentedon Jun 23, 2018
Traceback?
As long as you've provided a password at startup, it should just retry the login when the token expires. If you're using a Skype-only acccount, you can alternatively call
SkypeConnection.refresh()periodically, though I'm unsure if this still works following the switch to use the Live auth flow for Skype accounts.codeofdusk commentedon Jun 23, 2018
Terrance commentedon Jun 23, 2018
Presumably not token related (unless it happens immediately after the token expires?) -- looks like the connection is being interrupted somewhere higher up.
https://github.com/OllieTerrance/SkPy/blob/70a95e6866bfabdfdd4b739bab42f8e927e3f6af/skpy/main.py#L191-L198
SkypeEventLoopalready handles connection errors during the initial retrieval of events, though applying it toonEvent()call is a bit too wide in scope -- e.g. if you make further external requests, any connection errors will effectively abort the handler.Whilst some generic retry logic would be possible, I'd argue it's unsafe for any API methods with side-effects, such as in your case where you're sending a message (depending on when the connection was interrupted, it may or may not have gone through). For now, you'll need to add your own handling of connection errors and decide for each case whether a retry is sensible or not. Hopefully such connection errors are rare.
codeofdusk commentedon Jun 23, 2018
DerGenaue commentedon Jun 23, 2018
Interesting...
I just started toying around again with this and the normal
.getEvents()would fail every few minutes being closed remotely.Now everything is working fine, again
mtm-tin-naing-htun commentedon Jul 15, 2022
Why do not work Skype( username, password ) on heroku server? Token error is occured.
And, when Skype( username, password , token) is used , token is expired after 24 hrs and so, how to refresh token.