private void HttpClientSetHeaders(SemVersion version)
        {
            var headers = _httpClient.Value.DefaultRequestHeaders;

            headers.Clear();

            var os   = OperatingSystemProvider.GetInfo();
            var hwid = new Hash(LicenseSystemHardwareId ?? HardwareIdGenerator.GenerateHardwareId());

            headers.UserAgent.Add(new ProductInfoHeaderValue("CodeElementsUpdateSystem", "1.0"));
            headers.UserAgent.Add(new ProductInfoHeaderValue(
                                      $"({os.OperatingSystem + " " + os.Version.ToString(3)}; {CultureInfo.CurrentUICulture})"));
            headers.UserAgent.Add(new ProductInfoHeaderValue("app", version.ToString(true)));
            headers.UserAgent.Add(new ProductInfoHeaderValue($"({hwid})"));

            headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(ChangelogLanguage.TwoLetterISOLanguageName));
        }
Example #2
0
        /// <summary>
        /// Attempts to log in to a server with the given email address and password.
        /// </summary>
        /// <param name="server">The server to log in to</param>
        /// <param name="email">The user's email address</param>
        /// <param name="password">The user's password</param>
        /// <returns>A <see cref="AuthenticationInfo"/> instance with token/userID</returns>
        /// <exception cref="AuthenticationException">if there is an error while attempting to log in</exception>
        public async Task <AuthenticationInfo> LogInAsync(Server server, string email, string password)
        {
            var response = await new Url(server.ServerAddress).AppendPathSegments("User", "authenticateUser")
                           .SetQueryParam("email", email).SetQueryParam("password", HashUtil.HashSha1(password).ToLower())
                           .WithHeader("X-UserAgent",
                                       "GameLauncherReborn 2.0.8.8 WinForms (+https://github.com/worldunitedgg/GameLauncher_NFSW)")
                           .WithHeader("User-Agent", "GameLauncher (+https://github.com/SoapboxRaceWorld/GameLauncher_NFSW)")
                           .WithHeader("X-HWID", HardwareIdGenerator.GetHardwareIdentifier())
                           .WithHeader("X-GameLauncherHash", "aaaaa")
                           .AllowAnyHttpStatus()
                           .GetAsync();

            return(response.StatusCode switch
            {
                HttpStatusCode.OK => ParseToAuthenticationInfo(await response.Content.ReadAsStringAsync()),
                HttpStatusCode.Unauthorized => throw new AuthenticationException("Server rejected login from this launcher."),
                HttpStatusCode.InternalServerError => throw new AuthenticationException("Credentials rejected by server"),
                _ => throw new AuthenticationException("Cannot handle status code: " + response.StatusCode),
            });