Próbuję uwierzytelniać bez użycia tożsamości. Znalazłem kilka artykułów opisujących, jak to zrobić w innych wersjach, jednak nic w ASP.NET Core 2.Cookie Middleware bez Identity ASP.NET Rdzeń v2
Poniżej jest to, co skleciłem razem. Ale kiedy robi się SignInAsync jest wyjątek InvalidOperationException: No authentication handler is configured to handle the scheme: MyCookieMiddlewareInstance
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddCookieAuthentication("MyCookieMiddlewareInstance", o =>
{
o.LoginPath = new PathString("/Account/Login/");
o.AccessDeniedPath = new PathString("/Account/Forbidden/");
});
services.AddAuthentication();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseAuthentication();
}
public async Task<IActionResult> Login()
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, "joe nobody")
};
var identity = new ClaimsIdentity(claims, "MyCookieMiddlewareInstance");
var principal = new ClaimsPrincipal(identity);
//blows up on the following statement:
//InvalidOperationException: No authentication handler is configured to handle the scheme: MyCookieMiddlewareInstance
await HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance", principal);
return View();
}
Istnieje dokument Microsoft dla rdzenia asp.net v1.x (https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie) jednak IApplicationBuilder.UseCookieAuthentication() jest amortyzowana w v2 i nie znalazłem każdy roztwór.
nie jestem ustawiony tak, aby spróbować cokolwiek 2,0 spokrewnione, ale ja” jestem bardzo zainteresowany w swoim pytaniu, ponieważ wpłynie to na mnie. Jeśli spojrzeć na niektóre z ich testów jednostkowych, może być w stanie zorientować się, co najmniej, jakie obiekty powinny zadzwonić: https://github.com/aspnet/Identity/pull/1119/commits/2bdfdb3220b3aca7513455652617af5685d5293c –