Проверка подлинности файлов cookie с помощью расширения Chrome - PullRequest
2 голосов
/ 09 апреля 2019

Я пытаюсь аутентифицироваться в моем веб-приложении через расширение chrome, в данный момент данные отправляются нормально, но cookie-файл аутентификации не создается / не сохраняется.

Не уверен, что я делаю неправильно / если я хочу собрать информацию, относящуюся к вошедшему в систему пользователю, через расширение chrome, что будет лучшим способом сохранить вход в мое веб-приложение.

Контроллер входа

public bool Login()
        {
            try
            {
  Models.DatabaseModels.UserModel user = new Models.DatabaseModels.UserModel
                {
                    Username = Request.Headers["username"],
                    PasswordHash = PassHash(Request.Headers["password"])
                };

               if(_userRepo.Validate(user){
                var claims = new[] { new Claim(ClaimTypes.Name, user.Username),
                new Claim(ClaimTypes.Role, "User") };

                var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

                var authProperties = new AuthenticationProperties
                {
                    AllowRefresh = true,
                    ExpiresUtc = DateTimeOffset.Now.AddDays(1),
                    IsPersistent = true,
                };

                HttpContext.SignInAsync(
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    new ClaimsPrincipal(identity), authProperties);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
}
        }

startup.cs

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(o => o.LoginPath = new PathString("/"));

скрипт расширения chrome

$('#registerButton').on('click', function(e){
$.ajax({
    url:  'https://localhost:44327/Test/Login',
    headers: {
        username: $('#username').val(),
        password: $('#password').val()
    },
    type: "POST",
}).done(function (data){

});

});

...