Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

clientApi.AuthService.SendCodeAsync(phone).ConfigureAwait(false) doesnt work! #38

Open
emreordukaya opened this issue Jun 2, 2019 · 6 comments

Comments

@emreordukaya
Copy link

Hi I try to use this api but client doesnt work.

    public async void initClient()
    {
        var settings = new FactorySettings
        {
            AppHash = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",  // e.g 456a6654ad8f52c54bc4542505884cad
            AppId = xxxxxxx, // e.g 12345
            ServerAddress = "xxx.xxx.xxx.xx",   // e.g 149.154.167.50
            ServerPublicKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",   // e.g -----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAwVACPi9w23mF3tBk...
            ServerPort = xxx,  // e.g 443
            SessionTag = "Session", // by defaut
            Properties = new ApplicationProperties
            {
                AppVersion = "1.0.0", // You can leave as in the example
                DeviceModel = "PC", // You can leave as in the example
                LangCode = "en", // You can leave as in the example
                LangPack = "tdesktop", // You can leave as in the example
                SystemLangCode = "en", // You can leave as in the example
                SystemVersion = "Win 10 Pro" // You can leave as in the example
            }
        };

        // Create the client
        clientApi = await ClientFactory.BuildClientAsync(settings).ConfigureAwait(false);
        clientApi.KeepAliveConnection();

        clientApi.UpdatesService.AutoReceiveUpdates += update =>
        {
            Console.WriteLine($"updates: {JsonConvert.SerializeObject(update)}");
        };

        if (clientApi.AuthService.CurrentUserId.HasValue)
        {
            clientApi.UpdatesService.StartReceiveUpdates(TimeSpan.FromSeconds(1));
        }

        // If the user is not authenticated
        if (!clientApi.AuthService.CurrentUserId.HasValue)
        {
            // Auth
            var phone = "+90530xxxxxxx"; // User phone number with plus Turkey
            var sentCode = await clientApi.AuthService.SendCodeAsync(phone).ConfigureAwait(false);   // in this line I get System.NullReferanceExeeptions

            var code = "1234321"; // Sent code                
            try
            {
                user = await clientApi.AuthService.SignInAsync(phone, sentCode, code).ConfigureAwait(false);
            }
            // If the phone code is invalid
            catch (PhoneCodeInvalidException ex)
            {
            }
        }
        clientApi.UpdatesService.StartReceiveUpdates(TimeSpan.FromSeconds(1));
    }

System.NullReferanceExeeptions -->
Ekran Alıntısı

@mkd2380
Copy link

mkd2380 commented Jun 10, 2019

Me too . i have same problem

@emreordukaya
Copy link
Author

can any admin share docs or video how to use this project.?

@djonasdev
Copy link

I'm using the following code:

        private async Task _Connect()
        {
            Logger.Trace("Get client from client factory");
            //Create the client

            ClientApi = await ClientFactory.BuildClientAsync(Setting.GetFactorySettings()).ConfigureAwait(false);

            // If the user is not authenticated
            if (!ClientApi.AuthService.CurrentUserId.HasValue)
            {
                Logger.Trace($"Authenticate client '{Setting.PhoneNumber}' ..");
                // Auth
                var sentCode = await ClientApi.AuthService.SendCodeAsync(Setting.PhoneNumber).ConfigureAwait(false);

                TUser user;
                try
                {
                    Console.WriteLine($"Please insert authentication code '{Setting.PhoneNumber}'!",
                        "Authenticate code required");
                    var code = Console.ReadLine();

                    if (!string.IsNullOrEmpty(code))
                        user = await ClientApi.AuthService.SignInAsync(Setting.PhoneNumber, sentCode, code)
                            .ConfigureAwait(false);
                }
                // If the phone code is invalid
                catch (PhoneCodeInvalidException ex)
                {
                    Logger.Error(ex.Message);
                }
            }
        }

This works without any problems

@emreordukaya
Copy link
Author

emreordukaya commented Jul 6, 2019

at quick start (https://github.com/OpenTl/OpenTl.ClientApi/wiki/Quick-Start) settings variable like this;

 var settings = new FactorySettings
 {
      AppHash = // e.g 456a6654ad8f52c54bc4542505884cad
      AppId = // e.g 12345
      ServerAddress = // e.g 149.154.167.50
      ServerPublicKey = // e.g -----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAwVACPi9w23mF3tBk...
      ServerPort = // e.g 443
      SessionTag = "session", // by defaut
      Properties = new ApplicationProperties
           {
                AppVersion = "1.0.0", // You can leave as in the example
                DeviceModel = "PC", // You can leave as in the example
                LangCode = "en", // You can leave as in the example
                LangPack = "tdesktop", // You can leave as in the example
                SystemLangCode = "en", // You can leave as in the example
                SystemVersion = "Win 10 Pro" // You can leave as in the example
           }
      };

and code like here but doesnt work.

// Create the client
var clientApi = await ClientFactory.BuildClientAsync(settings).ConfigureAwait(false);

You wrote as a code that;

//Create the client
ClientApi = await ClientFactory.BuildClientAsync(Setting.GetFactorySettings()).ConfigureAwait(false);

But how did you define settings variable in your code.

in addition this I sent you an email for detail ;-)

@djonasdev
Copy link

Sorry my fault, here is my TClientSetting class:

 public class TClientSetting
    {
        public string AppHash { get; set; }
        public int AppId { get; set; }
        public string ServerAddress { get; set; }
        public string ServerPublicKey { get; set; }
        public int ServerPort { get; set; }
        public string PhoneNumber { get; set; }
        public string PhoneNumberSentCode { get; set; }
        public string SessionTag { get; set; }

        public List<ObservedEntity> ObservedEntities { get; set; } = new List<ObservedEntity>();

        public FactorySettings GetFactorySettings()
        {
            var settings = new FactorySettings
            {
                AppHash = AppHash,
                AppId = AppId,
                ServerAddress = ServerAddress,
                ServerPublicKey = ServerPublicKey,
                ServerPort = ServerPort,
                SessionTag = $"TSession_{PhoneNumber}", // by defaut
                Properties = new ApplicationProperties
                {
                    AppVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(), // You can leave as in the example
                    DeviceModel = "PC", // You can leave as in the example
                    LangCode = "de", // You can leave as in the example
                    LangPack = "tdesktop", // You can leave as in the example
                    SystemLangCode = "de", // You can leave as in the example
                    SystemVersion = "Win 10 Pro" // You can leave as in the example
                }
            };
            return settings;
        }
    }

@alessandrobernardin
Copy link

you have to use the certificate with "returns"
ServerPublicKey ="-----BEGIN RSA PUBLIC KEY-----\n" +
"MIIBCgKCAQEAwVACPi9w23mF3tBkdZz+zwrzKOaaQdr01vAbU4E1pvkfj4sqDsm6\n" +
"lyDONS789sVoD/xCS9Y0hkkC3gtL1tSfTlgCMOOul9lcixlEKzwKENj1Yz/s7daS\n" +
...
"-----END RSA PUBLIC KEY-----"

and work fine

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants