public IActionResult Validate([FromBody] TokenResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Token failed to generate"));
            }

            var user = _userService.FindByUsername(resource.Username);

            if (user == null)
            {
                return(Unauthorized());
            }

            if (!_userService.ValidateUser(user.UserName, resource.Password))
            {
                return(Unauthorized());
            }

            AppLogger.LogResourceRequest(nameof(Validate), user.UserName);

            var token = AppSecurity.GenerateToken(user.Id);

            _userService.StoreAccessToken(token, user.Id);

            return(Ok(token));
        }
        // Gets an access token for requests
        public static string GetAccessToken(string username = null)
        {
            using (var context = new LocalDbContext())
            {
                if (String.IsNullOrEmpty(username))
                {
                    username = "******";
                }

                var user = context.Users.Where(x => x.UserName == username).FirstOrDefault();

                if (user == null)
                {
                    return("");
                }

                var token = AppSecurity.GenerateToken(user.Id);

                return((token == null || String.IsNullOrEmpty(token.Token)) ? "" : token.Token);
            }
        }