Skip to content

Commit

Permalink
Fixed - Org App Session expiry redirect to home page stopped working (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmverma authored Oct 2, 2024
1 parent a5f7c33 commit c12e7bb
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using CO.CDP.OrganisationApp.Models;
using CO.CDP.OrganisationApp.Pages;

namespace CO.CDP.OrganisationApp;

public class AuthenticatedSessionAwareMiddleware(RequestDelegate next, ISession session)
{
public async Task Invoke(HttpContext context)
{
var endpoint = context.GetEndpoint();

if (endpoint != null)
{
if (endpoint.Metadata.GetMetadata<AuthenticatedSessionNotRequiredAttribute>() is null)
{
if (context.User.Identity?.IsAuthenticated == false)
{
context.Response.Redirect("/");
return;
}

var details = session.Get<UserDetails>(Session.UserDetailsKey);

if (details == null)
{
context.Response.Redirect("/");
return;
}
}
}

await next.Invoke(context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CO.CDP.OrganisationApp.Pages;

[AttributeUsage(AttributeTargets.Class)]
public class AuthenticatedSessionNotRequiredAttribute : Attribute
{
}
42 changes: 0 additions & 42 deletions Frontend/CO.CDP.OrganisationApp/Pages/AuthorisedSessionFilter.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Frontend/CO.CDP.OrganisationApp/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CO.CDP.OrganisationApp.Pages;

[AuthorisedSessionNotRequired]
[AuthenticatedSessionNotRequired]
public class ErrorModel : PageModel
{
public IActionResult OnGet()
Expand Down
2 changes: 1 addition & 1 deletion Frontend/CO.CDP.OrganisationApp/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace CO.CDP.OrganisationApp.Pages;

[AuthorisedSessionNotRequired]
[AuthenticatedSessionNotRequired]
public class IndexModel : PageModel
{
}
2 changes: 1 addition & 1 deletion Frontend/CO.CDP.OrganisationApp/Pages/OneLogin.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace CO.CDP.OrganisationApp.Pages.Registration;

[AuthorisedSessionNotRequired]
[AuthenticatedSessionNotRequired]
public class OneLogin(
IHttpContextAccessor httpContextAccessor,
IPersonClient personClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CO.CDP.OrganisationApp.Pages;

[AuthorisedSessionNotRequired]
[AuthenticatedSessionNotRequired]
public class PageNotFoundModel : PageModel
{
public IActionResult OnGet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace CO.CDP.OrganisationApp.Pages;

[AuthorisedSessionNotRequired]
[AuthenticatedSessionNotRequired]
public class PrivacyNoticeModel : PageModel
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CO.CDP.OrganisationApp.Pages.Users;

[AuthorisedSessionNotRequired]
[AuthenticatedSessionNotRequired]
public class OrganisationInviteModel : PageModel
{
public IActionResult OnGet(Guid personInviteId)
Expand Down
7 changes: 2 additions & 5 deletions Frontend/CO.CDP.OrganisationApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@
var builder = WebApplication.CreateBuilder(args);

var mvcBuilder = builder.Services.AddRazorPages()
.AddSessionStateTempDataProvider()
.AddMvcOptions(options =>
{
options.Filters.Add<AuthorisedSessionFilter>();
});
.AddSessionStateTempDataProvider();

if (builder.Environment.IsDevelopment())
{
Expand Down Expand Up @@ -189,6 +185,7 @@
app.UseRouting();
app.UseAuthentication();
app.UseSession();
app.UseMiddleware<AuthenticatedSessionAwareMiddleware>();
app.UseAuthorization();
app.MapRazorPages();

Expand Down

0 comments on commit c12e7bb

Please sign in to comment.