TLSharp icon indicating copy to clipboard operation
TLSharp copied to clipboard

AUTH_KEY_UNREGISTERED when using custom sessionUserId

Open messire opened this issue 8 years ago • 9 comments

Hi, guys! @sochix @marshallmick007 @ahmadalli @ra0o0f @Starli0n

What I do:

  1. Create client TelegramClient client = new TelegramClient(Api_Id, Api_Hash, sessionUserId: guid); bool connectionResult = await client.ConnectAsync(); string hash = await client.SendCodeRequestAsync(phone); TLUser user = await client.MakeAuthAsync(phone, hash, code);

It's ok on this step

  1. Then I close app and run again.
  2. TelegramClient client = new TelegramClient(Api_Id, Api_Hash, sessionUserId: guid); bool connectionResult = await client.ConnectAsync(); var dialogs = await client.GetUserDialogsAsync();

and now I have message 'AUTH_KEY_UNREGISTERED'


but if not using custom sessionUserId and creating and using by default new TelegramClient(Api_Id, Api_Hash) - it's all ok and no one error messages

messire avatar Dec 10 '17 06:12 messire

@messire try use TelegramClient insted of TLUser. Consider that sessionUserId is path to dat file with session.

AskoldMakaruk avatar Dec 10 '17 16:12 AskoldMakaruk

@AskoldMakaruk for example?

messire avatar Dec 11 '17 16:12 messire

@messire You can save dat files in current directory like this: string fullPathToDat = Directory.GetCurrentDirectory()+"\\filename.dat" Create .dat:

TelegramClient client = new TelegramClient(Api_Id, Api_Hash, new FileSessionStore(), fullPathToDat);
await client.ConnectAsync();
string hash = await client.SendCodeRequestAsync(phone);
await client.MakeAuthAsync(phone, hash, code);

Load .dat

var store = new FileSessionStore();
TelegramClient client = new TelegramClient(Api_Id, Hash, store, fullPathToDat);
await client.ConnectAsync();

AskoldMakaruk avatar Dec 11 '17 19:12 AskoldMakaruk

Hi I created and connected (ConnectAsync), sent the code and authed (MakeAuthAsync) this function successfully returned the TLUser object, also IsUserAuthorized returns true. At this time everything is ok and GetUserDialogsAsync is ok

Now if I close the program and start it again, despite IsUserAuthorized return true, but SendMessageAsync throws a AUTH_KEY_UNREGISTERED

The 'AUTH_KEY_UNREGISTERED' error is on :

var dialogs = (TLDialogs)await _client.GetUserDialogsAsync();

full code

        var store = new FileSessionStore();
        TelegramClient _client = new TelegramClient(11***9, "b****445dff9d19ff3631", store, "sessionName");
        await _client.ConnectAsync();

        if (!_client.IsUserAuthorized())
        {
            var hashKey = await _client.SendCodeRequestAsync("+********");
            TLUser myuser = await _client.MakeAuthAsync("+********", hashKey, TelegramSendedCode);
        }

        var dialogs = (TLDialogs)await _client.GetUserDialogsAsync();

I already test:

client.ConnectAsync()
client.IsUserAuthorized()
both TRUE

please help me tanks

Re3ar avatar Feb 06 '18 17:02 Re3ar

+1. The same problem.

GoldRat avatar Oct 13 '18 05:10 GoldRat

Some one solved this problem?

nikkozp avatar Feb 19 '19 13:02 nikkozp

Maybe ConnectAsync(reconnect = true) ?!

lazyjohny500 avatar May 23 '19 07:05 lazyjohny500

Hi! If you already have file session.dat, this works fo me: string fullPathToDat = Directory.GetCurrentDirectory() + "\session"; var store = new FileSessionStore(); client = new TelegramClient(apiId, apiHash, store, fullPathToDat); await client.ConnectAsync(false);

VDVuser avatar Nov 09 '19 09:11 VDVuser

Проблему решил используя client.ConnectAsync(false); Не знаю точно в чём проблема, но как мне кажется вопрос в методе обращения к серверу, в режиме Reconnect = true, каждое новое обращение к client меняет AuthKey и нужно после каждого обращения делать пересохранение сессии.

SovaSasha avatar Jul 01 '21 11:07 SovaSasha