Esempio n. 1
0
        public static HttpClient GetClient()
        {
            var uriApiWord = new BuilderHelper()._configuration["APIWord_Access:UrlBase"];

            var client = new HttpClient
            {
                BaseAddress = new Uri(uriApiWord)
            };

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept
            .Add(new MediaTypeWithQualityHeaderValue("application/json"));

            return(client);
        }
Esempio n. 2
0
        public static string GetLocation()
        {
            #region Another way to get file location
            //var location = Assembly.GetEntryAssembly().Location;
            //var dbFileLocation = "Context\\DataBase.db";
            //while (location.Contains("bin"))
            //{
            //    location = Path.GetDirectoryName(location);
            //}
            #endregion

            var dbFileLocation = new BuilderHelper()._configuration["DbSettings:MySql:DbFileLocation"];
            var location       = AppContext.BaseDirectory.Substring(0, AppContext.BaseDirectory.IndexOf("bin"));
            var dbPathFile     = Path.Combine(location, dbFileLocation);

            return(dbPathFile);
        }
Esempio n. 3
0
        public static object BuildToken()
        {
            var claims = new[] {
                new Claim(JwtRegisteredClaimNames.UniqueName, "UniqueName")
            };

            var key        = new BuilderHelper()._configuration["APIWord_Access:ApiKey"];
            var encodedKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
            var sign       = new SigningCredentials(encodedKey, SecurityAlgorithms.HmacSha256);
            var exp        = DateTime.UtcNow.AddHours(1);

            var token = new JwtSecurityToken(
                issuer: null,
                audience: null,
                claims: claims,
                expires: exp,
                signingCredentials: sign
                );

            var stringToken = new JwtSecurityTokenHandler().WriteToken(token);

            return(new { token = stringToken, expirationDate = exp });
        }