Пример #1
0
        public static async Task <string> SetupNexusLogin(BaseCefBrowser browser, Action <string> updateStatus, CancellationToken cancel)
        {
            updateStatus("Please Log Into the Nexus");
            browser.Address = "https://users.nexusmods.com/auth/continue?client_id=nexus&redirect_uri=https://www.nexusmods.com/oauth/callback&response_type=code&referrer=//www.nexusmods.com";
            while (true)
            {
                var cookies = await Helpers.GetCookies("nexusmods.com");

                if (cookies.Any(c => c.Name == "member_id"))
                {
                    break;
                }
                cancel.ThrowIfCancellationRequested();
                await Task.Delay(500, cancel);
            }

            // open a web socket to receive the api key
            var guid = Guid.NewGuid();

            using (var websocket = new WebSocket("wss://sso.nexusmods.com")
            {
                SslConfiguration =
                {
                    EnabledSslProtocols = SslProtocols.Tls12
                }
            })
            {
                updateStatus("Please Authorize Wabbajack to Download Mods");
                var api_key = new TaskCompletionSource <string>();
                websocket.OnMessage += (sender, msg) => { api_key.SetResult(msg.Data); };

                websocket.Connect();
                websocket.Send("{\"id\": \"" + guid + "\", \"appid\": \"" + Consts.AppName + "\"}");
                await Task.Delay(1000, cancel);

                // open a web browser to get user permission
                browser.Address = $"https://www.nexusmods.com/sso?id={guid}&application={Consts.AppName}";
                using (cancel.Register(() =>
                {
                    api_key.SetCanceled();
                }))
                {
                    return(await api_key.Task);
                }
            }
        }
Пример #2
0
        public static async Task <Helpers.Cookie[]> GetAndCacheLoversLabCookies(BaseCefBrowser browser, Action <string> updateStatus, CancellationToken cancel)
        {
            updateStatus("Please Log Into Lovers Lab");
            browser.Address = "https://www.loverslab.com/login";

            async Task <bool> CleanAds()
            {
                try
                {
                    await browser.EvaluateJavaScript <string>(
                        "document.querySelectorAll(\".ll_adblock\").forEach(function (itm) { itm.innerHTML = \"\";});");
                }
                catch (Exception ex)
                {
                    Utils.Error(ex);
                }
                return(false);
            }

            var cookies = new Helpers.Cookie[0];

            while (true)
            {
                cancel.ThrowIfCancellationRequested();
                await CleanAds();

                cookies = (await Helpers.GetCookies("loverslab.com"));
                if (cookies.FirstOrDefault(c => c.Name == "ips4_member_id") != null)
                {
                    break;
                }
                await Task.Delay(500, cancel);
            }

            cookies.ToEcryptedJson("loverslabcookies");

            return(cookies);
        }