Я пытаюсь включить мою пользовательскую схему аутентификации, к сожалению, после установки значения USER.IDENTITY.IsAuthentication в true после успешного обхода моей функции входа в систему AuthorizeFilter по-прежнему отказывает в доступе к приложению.
Пожалуйста, помогите, я прикрепил изображения кода.
[startup][1]
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
var mappingConfig = new MapperConfiguration(mc =>
{
mc.AddProfile(new MappingProfile());
});
IMapper mapper = mappingConfig.CreateMapper();
services.AddSingleton(mapper);
services.AddDbContext<AwmDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddScoped<IUsersLogic, UsersLogic>();
services.AddScoped<IUsersRepo, Repo.UsersRepo>();
services.AddAuthentication(options => {
options.DefaultSignInScheme = "FiverSecurityScheme";
options.DefaultScheme = "FiverSecurityScheme";
options.DefaultAuthenticateScheme = "FiverSecurityScheme";
})
.AddCookie("FiverSecurityScheme", options =>
{
options.AccessDeniedPath = new PathString("/Users/Login");
options.LoginPath = new PathString("/Users/Login");
});
services.AddAuthorization();
services.AddMvc () SetCompatibilityVersion (CompatibilityVersion.Version_2_1).
}
[startup-config services][2]
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areas",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
});
}
[login code] [3]
public async Task<bool> LoginUser(LoginViewModel login, HttpContext context
)
{
var userFound = await _usersRepo.LoginUser(login.UserName);
AuthenticationTicket ticket;
if (IsPasswordMatch(login.UserPassword, userFound.Salt.TrimEnd(), userFound.Password.TrimEnd()))
{
// create claims
List<Claim> claims = new List<Claim>
{
new Claim(ClaimTypes.Name, login.UserName),
new Claim(ClaimTypes.Email, "mihail@abv.bg")
};
// create identity
ClaimsIdentity identity = new ClaimsIdentity(claims, "FiverSecurityScheme");
// create principal
//ClaimsPrincipal principal = new ClaimsPrincipal(identity);
var principal = new ClaimsPrincipal(new[] { identity });
Thread.CurrentPrincipal = principal;
context.User = principal;
// sign-in
await context.SignInAsync("FiverSecurityScheme", principal);
return (true);
}
else
return false;
}