Problème de redirect de l'API corrigé.
This commit is contained in:
@@ -23,8 +23,27 @@ builder.Services.AddCors(options => {
|
||||
});
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddAuthentication().AddIdentityCookies();
|
||||
|
||||
// Source: https://github.com/dotnet/aspnetcore/issues/9039
|
||||
builder.Services.ConfigureApplicationCookie(o => {
|
||||
o.Events = new CookieAuthenticationEvents() {
|
||||
OnRedirectToLogin = (ctx) => {
|
||||
if (ctx.Request.Path.StartsWithSegments("/api") && ctx.Response.StatusCode == 200) {
|
||||
ctx.Response.StatusCode = 401;
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
},
|
||||
OnRedirectToAccessDenied = (ctx) => {
|
||||
if (ctx.Request.Path.StartsWithSegments("/api") && ctx.Response.StatusCode == 200) {
|
||||
ctx.Response.StatusCode = 403;
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddAuthentication("Cookies").AddIdentityCookies();
|
||||
builder.Services.AddIdentityCore<InventoryUser>()
|
||||
.AddRoles<IdentityRole>()
|
||||
.AddEntityFrameworkStores<InventoryContext>()
|
||||
@@ -52,7 +71,6 @@ if (app.Environment.IsDevelopment()) {
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseCors(MyAllowSpecificOrigins);
|
||||
|
||||
app.UseAuthorization();
|
||||
app.UseAuthentication();
|
||||
|
||||
|
Reference in New Issue
Block a user