Beispiel #1
0
        public static void AddAuthenticationUser(string clientId, string clientSecret)
        {
            var authResponse = TwitchAuthentication.Authenticate(clientId, clientSecret, url => {
                TwitchAuthenticationWindow authentWindow = new TwitchAuthenticationWindow(url);
                authentWindow.ShowDialog();

                return(authentWindow.Url);
            });

            if (authResponse is SuccessfulAuthentication success)
            {
                MainAdmin.TwitchUserTokenDict.Add(success.Name, success.Token);
            }
        }
Beispiel #2
0
        private static async Task StartBot(string directory, Config config)
        {
            string accessToken = string.Empty;
            string path        = Path.Combine(directory, "Token.txt");

            if (File.Exists(path))
            {
                try
                {   // Open the text file using a stream reader.
                    using (StreamReader sr = new StreamReader(path))
                    {
                        string line = sr.ReadLine();
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            string[] items = line.Split('|');
                            if (items.Length == 2 && items[0] == config.user)
                            {
                                accessToken = items[1];
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("The file could not be read: {0}", e.Message);
                }
            }

            IAuthenticationResult result;

            if (!string.IsNullOrWhiteSpace(accessToken))
            {
                result = new SuccessfulAuthentication(config.user, accessToken);
            }
            else
            {
                result = await TwitchAuthentication.Auth(config.clientId, config.clientSecret, config.redirectUri);

                if (result is SuccessfulAuthentication suc)
                {
                    File.WriteAllLines(path, new[] { string.Format("{0}|{1}", suc.Name, suc.Token) });
                }
            }

            if (result is SuccessfulAuthentication success)
            {
                await RunBot(directory, success.Token, config);
            }
        }
Beispiel #3
0
        private static Client AuthenticateLogin(string[] args)
        {
            Console.WriteLine("Login user: "******"Too few arguments!");
                    Console.WriteLine("Usage: {0} <client id> <client secret>", Environment.GetCommandLineArgs()[0]);
                    Environment.Exit(1);
                    return(null);
                }

                string clientId     = args[0];
                string clientSecret = args[1];

                authResponse = TwitchAuthentication.Authenticate(clientId, clientSecret, url => {
                    Console.WriteLine("Log in URL:");
                    Console.WriteLine(url);
                    return(Console.ReadLine());
                });
                newToken = true;
            }

            if (authResponse is SuccessfulAuthentication success)
            {
                // When new Token add Token to DB
                if (newToken)
                {
                    MainAdmin.AddAccesToken(success.Name, success.Token);
                }

                Console.WriteLine("Authentication Success");

                CliClientHandler clientHandler = new CliClientHandler();
                Client           client        = new Client(success.Name, success.Token, clientHandler);
                client.Connect();

                return(client);
            }
            else
            {
                var failure = authResponse as FailedAuthentication;
                Console.WriteLine("Authentication Failure: {0}; Reason: {1}", failure.Failure, failure.Reason);

                Console.ReadKey();
            }
            return(null);
        }