Example #1
0
        public static Tuple <string, string> Validate(string token)
        {
            GetRequest req = new GetRequest("https://api.twitch.tv/kraken");

            req.AddHeader(HttpRequestHeader.Authorization, "OAuth " + token);
            req.AddHeader(HttpRequestHeader.Accept, "application/vnd.twitchtv.v5+json");

            JObject resp     = req.GetResponseJson();
            string  userId   = (string)resp["token"]["user_id"];
            string  username = (string)resp["token"]["user_name"];

            return(new Tuple <string, string>(userId, username));
        }
Example #2
0
        public void GetUserJohn(userJohn req)
        {
            userJohn req = new GetRequest("John");

            req.AddHeader("Autorization", "Bearer HHCL109yiUfnNcI4oj1YARq08eNr-ZkafTPw");
            var response = Client.Get(req);
        }
Example #3
0
        public static IActionResult Subscribers(RequestHandler <IActionResult> req)
        {
            int limit = 100;
            int total = int.MaxValue;

            User user = UserManager.GetUserTwitch("gogomic");

            JArray           subs = new JArray();
            HashSet <string> ids  = new HashSet <string>();

            for (int offset = 0; offset + limit <= total; offset += limit)
            {
                UrlParams param = new UrlParams();
                param.Add("limit", limit.ToString());
                param.Add("offset", offset.ToString());

                // TODO: Chain requests if gogomic ever gets over 100 subs.
                string url = "https://api.twitch.tv/kraken/channels/" + user.TwitchId
                             + "/subscriptions" + param.ToString();

                GetRequest getReq = new GetRequest(url);

                getReq.AddHeader(HttpRequestHeader.Accept, "application/vnd.twitchtv.v5+json");
                getReq.AddHeader("Client-ID", Config.TwitchOAuth.ClientId);
                getReq.AddHeader("Authorization", "OAuth " + user.TwitchToken);

                JObject resp = getReq.GetResponseJson();

                foreach (JToken sub in (JArray)resp["subscriptions"])
                {
                    string id = (string)sub["user"]["_id"];

                    if (ids.Contains(id) || id == user.TwitchId)
                    {
                        continue;
                    }

                    ids.Add(id);
                    subs.Add(sub);
                }

                total = (int)resp["_total"];
            }

            req.View.Subs = subs;
            return(req.Controller.View());
        }
Example #4
0
        static void Main(string[] args)
        {
            // Each ngs account has two parameters : User, Password
            var user     = "******";          // !!! rewrite value from your account !!!
            var password = "******";      // !!! rewrite value from your account !!!

            // We keep cookies here
            var cookies = new CookieContainer();

            // Any proxy, for example Fiddler
            var proxy = new WebProxy("127.0.0.1:8888");

            // This portal uses basic authorization:

            // We need to create auth string
            var authString = $"{user}:{password}".ToBase64();

            var getRequest = new GetRequest()
            {
                Address   = "https://ngs.ru/",
                Accept    = "text/html, application/xhtml+xml, image/jxr, */*",
                Host      = "ngs.ru",
                KeepAlive = true,
                Proxy     = proxy
            };

            getRequest.AddHeader("Authorization", $"Basic {authString}");
            getRequest.Run(ref cookies);

            // Auth request doesn't need, only adding an auth header
            var postRequest = new PostRequest()
            {
                Data      = "",
                Address   = $"https://newsapi.ngs.ru/v1/public/account/?regionId=54",
                Accept    = "vnd.news.v1.jtnews+json",
                Host      = "newsapi.ngs.ru",
                Referer   = "https://ngs.ru/",
                KeepAlive = true,
                Proxy     = proxy
            };

            postRequest.AddHeader("Origin", "https://ngs.ru");
            postRequest.AddHeader("Authorization", $"Basic {authString}");
            postRequest.Run(ref cookies);

            var validIndex = getRequest.Response.Contains("userId\":");

            if (validIndex)
            {
                Config.Instance.AddLogInfo($"Auth result: successful");
            }
            else
            {
                Config.Instance.AddLogInfo($"Auth result: unknown, something was wrong");
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            // Each blablacar account has two parameters : User, Password
            var user     = "******";          // !!! rewrite value from your account !!!
            var password = "******";      // !!! rewrite value from your account !!!

            // We keep cookies here
            var cookies = new CookieContainer();

            // Any proxy, for example Fiddler
            var proxy = new WebProxy("127.0.0.1:8888");

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var getRequest = new GetRequest()
            {
                Address   = "https://www.blablacar.ru/",
                Accept    = "text/html, application/xhtml+xml, image/jxr, */*",
                Host      = "www.blablacar.ru",
                KeepAlive = true,
                UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
                Proxy     = proxy
            };

            getRequest.Run(ref cookies);

            // We should to find visitor value
            var visitorStart = getRequest.Response.IndexOf("visitorId") + 12;
            var visitorEnd   = getRequest.Response.IndexOf("\"", visitorStart);
            var visitor      = getRequest.Response.Substring(visitorStart, visitorEnd - visitorStart);

            // Random value
            var xCorrelationId = "b4a8fe14-7a1c-4de6-8c13-9edbb6f7c1a5";

            // Auth request
            var data        = $"{{\"login\":\"{user}\",\"password\":\"{password}\",\"rememberMe\":true,\"grant_type\":\"password\"}}";
            var postRequest = new PostRequest()
            {
                Data        = data,
                Address     = $"https://auth.blablacar.ru/secure-token",
                Accept      = "application/json",
                Host        = "auth.blablacar.ru",
                ContentType = "application/json",
                Referer     = "https://www.blablacar.ru/login/email",
                KeepAlive   = true,
                Proxy       = proxy
            };

            postRequest.AddHeader("x-client", "SPA|1.0.0");
            postRequest.AddHeader("x-correlation-id", xCorrelationId);
            postRequest.AddHeader("x-currency", "RUB");
            postRequest.AddHeader("x-forwarded-proto", "https");
            postRequest.AddHeader("x-locale", "ru_RU");
            postRequest.AddHeader("x-visitor-id", visitor);
            postRequest.AddHeader("Origin", "https://www.blablacar.ru");
            postRequest.Run(ref cookies);

            // Finding this cookie value from all the headers
            var bearerCookieValue = string.Empty;
            var headers           = postRequest.ResponseHeaders;

            for (int i = 0; i < headers.Count; ++i)
            {
                string header = headers.GetKey(i);

                if (header == "Set-Cookie")
                {
                    var headerValue = headers.GetValues(i)[0];
                    headerValue = WebUtility.UrlDecode(headerValue);

                    var accessTokenStart = postRequest.Response.IndexOf("access_token") + 15;
                    var accessTokenEnd   = postRequest.Response.IndexOf("\"", accessTokenStart);
                    bearerCookieValue = postRequest.Response.Substring(accessTokenStart, accessTokenEnd - accessTokenStart);
                }
            }

            // For example we want to know all the trips from this account
            getRequest = new GetRequest()
            {
                Address     = "https://edge.blablacar.ru/bookings-and-tripoffers?active=false",
                Accept      = "application/json",
                Host        = "edge.blablacar.ru",
                KeepAlive   = true,
                ContentType = "application/json",
                Referer     = "https://www.blablacar.ru/rides/history",
                Proxy       = proxy
            };
            getRequest.AddHeader("x-blablacar-accept-endpoint-version", "2");
            getRequest.AddHeader("x-client", "SPA|1.0.0");
            getRequest.AddHeader("x-correlation-id", xCorrelationId);
            getRequest.AddHeader("x-currency", "RUB");
            getRequest.AddHeader("x-forwarded-proto", "https");
            getRequest.AddHeader("x-locale", "ru_RU");
            getRequest.AddHeader("x-visitor-id", visitor);
            getRequest.AddHeader("authorization", $"Bearer {bearerCookieValue}");
            getRequest.AddHeader("Origin", "https://www.blablacar.ru");
            getRequest.Run(ref cookies);

            // Write to log the json response with all the account trips
            Config.Instance.AddLogInfo(getRequest.Response);
        }