Skip to content

Commit

Permalink
Fix auth issue
Browse files Browse the repository at this point in the history
  • Loading branch information
miroljub1995 committed Sep 21, 2024
1 parent 53b77ae commit aaff662
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion backend/ResQueue/ResQueue/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AspNetCore.Identity.Mongo;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Rewrite;
using MongoDB.Bson;
Expand Down Expand Up @@ -86,7 +87,23 @@ public static void Main(string[] args)
builder.Services.AddTransient<IChangeCardFeature, ChangeCardFeature>();
builder.Services.AddTransient<IEventHandlerFeature, EventHandlerFeature>();

builder.Services.ConfigureApplicationCookie(options => { options.ExpireTimeSpan = TimeSpan.FromDays(30); });
builder.Services.ConfigureApplicationCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromDays(30);
options.Events = new CookieAuthenticationEvents
{
OnRedirectToLogin = ctx =>
{
ctx.Response.StatusCode = StatusCodes.Status401Unauthorized;
return Task.CompletedTask;
},
OnRedirectToAccessDenied = ctx =>
{
ctx.Response.StatusCode = StatusCodes.Status403Forbidden;
return Task.CompletedTask;
}
};
});

builder.Services.AddAuthorization();

Expand Down

0 comments on commit aaff662

Please sign in to comment.