Example #1
0
        public bool LoginWithToken()
        {
            var authToken = Config.GetParameterValue("AuthToken") as string;
            var userName  = Config.GetParameterValue("Username") as string;

            NickName = userName;

            var password         = Config.GetParameterValue("Password") as string;
            var tokenCredentials = Config.GetParameterValue("AuthTokenCredentials") as string;

            if (tokenCredentials != userName + password)
            {
                Config.SetParameterValue("AuthToken", String.Empty);
                return(false);
            }

            if (String.IsNullOrEmpty(userName))
            {
                IsAnonymous = true;
                return(true);
            }

            if (String.IsNullOrWhiteSpace(authToken))
            {
                return(false);
            }

            loginWebClient.SetCookie("kname", userName, "cybergame.tv");
            loginWebClient.SetCookie("khash", userName, "cybergame.tv");

            var test = this.With(x => loginWebClient.Download("http://cybergame.tv"));

            if (test != null && test.Contains("logout.php"))
            {
                return(true);
            }

            Config.SetParameterValue("AuthToken", String.Empty);

            return(false);
        }
Example #2
0
        public bool LoginWithUsername()
        {
            var userName = Config.GetParameterValue("Username") as string;
            var password = Config.GetParameterValue("Password") as string;

            if (String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(password) || userName.Equals(AnonymousNickName, StringComparison.InvariantCultureIgnoreCase))
            {
                IsAnonymous = true;
                return(true);
            }

            if (Regex.IsMatch(userName, @"justinfan\d+"))
            {
                AnonymousNickName = userName;
            }

            NickName = userName;

            webClient.SetCookie("api_token", null, "twitch.tv");
            webClient.SetCookie("csrf_token", null, "twitch.tv");

            var csrfToken = this.With(x => webClient.Download("http://www.twitch.tv/login"))
                            .With(x => Re.GetSubString(x, @"^.*authenticity_token.*?value=""(.*?)"""));


            if (csrfToken == null)
            {
                Log.WriteError("Twitch: Can't get CSRF token. Twitch web layout changed ?");
                return(false);
            }
            string csrf_cookie = csrfToken;

            if (csrf_cookie.Substring(csrf_cookie.Length - 1).Equals("="))
            {
                csrf_cookie = csrf_cookie.Substring(0, csrf_cookie.Length - 1) + "%3D";
            }

            webClient.SetCookie("csrf_token", csrf_cookie, "twitch.tv");
            webClient.ContentType = ContentType.UrlEncoded;
            webClient.Headers["X-Requested-With"] = "XMLHttpRequest";
            webClient.Headers["X-CSRF-Token"]     = csrfToken;
            webClient.Headers["Accept"]           = "text/html, application/xhtml+xml, */*";

            var apiToken = this.With(x => webClient.Upload("https://secure.twitch.tv/user/login", String.Format(
                                                               "utf8=%E2%9C%93&authenticity_token={0}%3D&redirect_on_login=&embed_form=false&user%5Blogin%5D={1}&user%5Bpassword%5D={2}",
                                                               csrfToken,
                                                               userName,
                                                               password)))
                           .With(x => webClient.CookieValue("api_token", "http://twitch.tv"));

            if (String.IsNullOrWhiteSpace(apiToken))
            {
                Log.WriteError("Twitch: Can't get API token");
                return(false);
            }
            webClient.Headers["Twitch-Api-Token"] = apiToken;
            webClient.Headers["X-CSRF-Token"]     = csrfToken;
            webClient.Headers["Accept"]           = "*/*";

            if (apiToken == null)
            {
                Log.WriteError("Login to twitch.tv failed. Joining anonymously");
                IsAnonymous = true;
                return(false);
            }
            else
            {
                var oauthToken = this.With(x => webClient.Download("http://api.twitch.tv/api/me?on_site=1"))
                                 .With(x => JToken.Parse(x))
                                 .With(x => x.Value <string>("chat_oauth_token"));

                if (String.IsNullOrWhiteSpace(oauthToken))
                {
                    Log.WriteError("Login to twitch.tv failed. Joining anonymously");
                    IsAnonymous = true;
                    return(false);
                }

                IsAnonymous = false;
                Config.SetParameterValue("OAuthToken", oauthToken);
                Config.SetParameterValue("ApiToken", apiToken);
                Config.SetParameterValue("AuthTokenCredentials", userName + password);

                return(LoginWithToken());
            }
        }
Example #3
0
        private bool LoginWithToken()
        {
            var authToken        = Config.GetParameterValue("AuthToken") as string;
            var userName         = Config.GetParameterValue("Username") as string;
            var password         = Config.GetParameterValue("Password") as string;
            var tokenCredentials = Config.GetParameterValue("AuthTokenCredentials") as string;

            if (tokenCredentials != userName + password)
            {
                return(false);
            }

            if (String.IsNullOrEmpty(userName))
            {
                IsAnonymous = true;
                ResetAuthData();
                return(true);
            }

            if (String.IsNullOrWhiteSpace(authToken))
            {
                return(false);
            }

            NickName = userName;

            webClient.SetCookie("PHPSESSID", authToken, "goodgame.ru");

            var content = GoodgameGet("http://goodgame.ru/chat/");

            if (String.IsNullOrWhiteSpace(content))
            {
                return(false);
            }

            uint userId = 0;

            if (!UInt32.TryParse(Re.GetSubString(content, @"userId.*?(\d+)"), out userId))
            {
                IsAnonymous = true;
                ResetAuthData();
                return(false);
            }
            else
            {
                if (userId == 0)
                {
                    LoginWithUsername();
                }

                IsAnonymous       = false;
                Info.CanBeRead    = true;
                Info.CanBeChanged = true;
                Config.SetParameterValue("AuthToken", authToken);
                Config.SetParameterValue("AuthTokenCredentials", userName + password);
                Config.SetParameterValue("ChatToken", Re.GetSubString(content, @"token.*?'(.*?)'"));
                Config.SetParameterValue("UserId", userId.ToString());
            }

            return(true);
        }