У меня простая настройка API с Asp Identity, маршруты входа в систему, создания и 2fa работают нормально, но когда я пытаюсь позвонить и выйти, я получаю следующий ответ об ошибке:
Система .InvalidOperationException: для схемы Identity.Application не зарегистрирован обработчик аутентификации при выходе. Зарегистрированные схемы выхода: Identity.Bearer. Вы забыли вызвать AddAuthentication().AddCookie("Identity.Application",...)?
в Microsoft.AspNetCore.Authentication.AuthenticationService.SignOutAsync(контекст HttpContext, строковая схема, свойства AuthenticationProperties)
в Microsoft.AspNetCore.Identity.SignInManager`1.SignOutAsync()
в Program.c.d.MoveNext()
моей программе. cs, есть ли какие-либо изменения в конфигурации, которые мне здесь не хватает?
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext(options => options.UseNpgsql("Server=localhost;Database=PartnerPortal;Port=5432;User Id=postgres;Password=Password@1;Ssl Mode=Prefer;"));
builder.Services.AddIdentityCore()
.AddEntityFrameworkStores()
.AddApiEndpoints() ;
builder.Services.Configure(options =>
{
options.SignIn.RequireConfirmedEmail = true;
});
builder.Services.AddTransient();
builder.Services.AddAuthentication().AddBearerToken(IdentityConstants.BearerScheme);
builder.Services.AddAuthorizationBuilder();
builder.Services.AddControllers();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.MapGroup("/account").MapIdentityApi();
app.MapGroup("/account").MapPost("/logout", async (SignInManager signInManager,
[FromBody] object empty) =>
{
if (empty != null)
{
await signInManager.SignOutAsync();
return Results.Ok();
}
return Results.Unauthorized();
})
.WithOpenApi()
.RequireAuthorization();
app.MapGet("/test", (ClaimsPrincipal user) => $"Hello {user.Identity.Name}").RequireAuthorization();
app.MapControllers();
app.Run();
public class AgentPortalUser : IdentityUser;
class AppDbContext : IdentityDbContext
{
public AppDbContext(DbContextOptions options) : base(options) { }
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... s-register
System.InvalidOperationException: для схемы не зарегистрирован обработчик аутентификации при выходе. ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение