wiz0u / WTelegramClient

Telegram Client API (MTProto) library written 100% in C# and .NET
https://wiz0u.github.io/WTelegramClient/
MIT License
956 stars 156 forks source link

Interrupted login (resumed/asynchronous) #243

Closed aneillans closed 5 months ago

aneillans commented 5 months ago

Is it possible to interrupt, destroy and recreate the client between the auth sms (when the phone number is provided) and the auth code is provided steps? From what I can make out from the documentation it should be, but when I try (breaking the sample console app, and simply swapping out the mobile number for the auth code) TG api responds with "Invalid Phone Number" so clearly trying to parse the auth code as a number. Guessing the state isn't getting reused and it's restarting the auth flow.

wiz0u commented 5 months ago

Which login method are you using?

aneillans commented 5 months ago

I have unashamedly ripped off the sample here: https://github.com/wiz0u/WTelegramClient?tab=readme-ov-file#alternative-simplified-configuration--login :) (So using the client.Login method)

Which login method are you using?

wiz0u commented 5 months ago

ok so what's the problem when you interrupt (break the while loop), destroy (Dispose) and recreate the client?

aneillans commented 5 months ago

The second pass (time) I call Login (with the code) I get 400 PHONE_NUMBER_INVALID back. Looks like the state isnt used; I would not have expected the auth session to have expired, given it was only a few seconds prior.

I can see from the startup of the client that the session data was loaded however.

wiz0u commented 5 months ago

oh I understand.

No with Login or LoginUserIfNeeded methods, you cannot Dispose the client in the middle of the login sequence, and resume it at that point, you have to restart with the phone_number. Resuming the session (with the session file data, as described in the readme) works only with a fully logged-in user.

You may try to achieve what you want by calling the Auth_* methods manually, but I'm not sure it works and I highly advise against doing that