Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show info on how to enable server side sessions when disabled #899

Merged
merged 1 commit into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hosts/EntityFramework/IdentityServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal static WebApplicationBuilder ConfigureIdentityServer(this WebApplicatio
options.RemoveConsumedTokens = true;
options.TokenCleanupInterval = 10; // interval in seconds
})
.AddServerSideSessions()
//.AddServerSideSessions()
// this is something you will want in production to reduce load on and requests to the DB
//.AddConfigurationStoreCache()
;
Expand Down
201 changes: 107 additions & 94 deletions hosts/EntityFramework/Pages/ServerSideSessions/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,111 +3,124 @@
@{
}


<div class="users-page">
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
<h2>User Sessions</h2>
</div>

<div class="card-body">
<div class="row">
<div class="col text-center">
@if (Model.UserSessions.HasPrevResults)
{
<a class="btn btn-primary" asp-page="/ServerSideSessions/Index" asp-route-prev="true" asp-route-filter="@Model.Filter" asp-route-token="@Model.UserSessions.ResultsToken">Prev</a>
}
</div>
<form class="col">
<div class="form-inline">
<label asp-for="@Model.Filter">Filter:</label>
<input type="search" asp-for="@Model.Filter" class="form-control" autofocus />
<button type="submit" class="form-control btn btn-success">Search</button>
</div>
</form>
<div class="col text-center">
@if (Model.UserSessions.HasNextResults)
{
<a class="btn btn-primary" asp-page="/ServerSideSessions/Index" asp-route-filter="@Model.Filter" asp-route-token="@Model.UserSessions.ResultsToken">Next</a>
}
</div>
<div class="users-page">
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
<h2>User Sessions</h2>
</div>

<div class="card-body">

@if(Model.UserSessions.TotalCount.HasValue)
@if (Model.UserSessions != null)
{
<div class="text-center">
@if(Model.UserSessions.CurrentPage.HasValue && Model.UserSessions.TotalPages.HasValue)
{
<text>
Total Results: @Model.UserSessions.TotalCount,
Page @Model.UserSessions.CurrentPage of @Model.UserSessions.TotalPages
</text>
}
else
{
<text>
Total Results: @Model.UserSessions.TotalCount
</text>
}
<div class="row">
<div class="col text-center">
@if (Model.UserSessions.HasPrevResults)
{
<a class="btn btn-primary" asp-page="/ServerSideSessions/Index" asp-route-prev="true" asp-route-filter="@Model.Filter" asp-route-token="@Model.UserSessions.ResultsToken">Prev</a>
}
</div>
<form class="col">
<div class="form-inline">
<label asp-for="@Model.Filter">Filter:</label>
<input type="search" asp-for="@Model.Filter" class="form-control" autofocus />
<button type="submit" class="form-control btn btn-success">Search</button>
</div>
</form>
<div class="col text-center">
@if (Model.UserSessions.HasNextResults)
{
<a class="btn btn-primary" asp-page="/ServerSideSessions/Index" asp-route-filter="@Model.Filter" asp-route-token="@Model.UserSessions.ResultsToken">Next</a>
}
</div>
</div>
}

<br />
@if (Model.UserSessions.TotalCount.HasValue)
{
<div class="text-center">
@if (Model.UserSessions.CurrentPage.HasValue && Model.UserSessions.TotalPages.HasValue)
{
<text>
Total Results: @Model.UserSessions.TotalCount,
Page @Model.UserSessions.CurrentPage of @Model.UserSessions.TotalPages
</text>
}
else
{
<text>
Total Results: @Model.UserSessions.TotalCount
</text>
}
</div>
}

<br />

@if (Model.UserSessions.Results.Any())
{
<div>
<table class="table table-bordered table-striped table-sm">
<thead>
<tr>
<th>Subject Id</th>
<th>Session Id</th>
<th>Display Name</th>
<th>Created</th>
<th>Expires</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var session in Model.UserSessions.Results)
{
@if (Model.UserSessions.Results.Any())
{
<div>
<table class="table table-bordered table-striped table-sm">
<thead>
<tr>
<td>@session.SubjectId</td>
<td>@session.SessionId</td>
<td>@session.DisplayName</td>
<td>@session.Created</td>
<td>@session.Expires</td>
<td>
<form method="post">
<input type="hidden" name="SessionId" value="@session.SessionId" />
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
<th>Subject Id</th>
<th>Session Id</th>
<th>Display Name</th>
<th>Created</th>
<th>Expires</th>
<th></th>
</tr>
<tr><td colspan="6">
<strong>Clients:</strong>
@if (session.ClientIds?.Any() == true)
{
@(session.ClientIds.Aggregate((x, y) => $"{x}, {y}"))
}
else
{
@("None")
}
</td></tr>
}
</tbody>
</table>
</div>
</thead>
<tbody>
@foreach (var session in Model.UserSessions.Results)
{
<tr>
<td>@session.SubjectId</td>
<td>@session.SessionId</td>
<td>@session.DisplayName</td>
<td>@session.Created</td>
<td>@session.Expires</td>
<td>
<form method="post">
<input type="hidden" name="SessionId" value="@session.SessionId" />
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<tr><td colspan="6">
<strong>Clients:</strong>
@if (session.ClientIds?.Any() == true)
{
@(session.ClientIds.Aggregate((x, y) => $"{x}, {y}"))
}
else
{
@("None")
}
</td></tr>
}
</tbody>
</table>
</div>
}
else
{
<div class="text-center">No User Sessions</div>
}
}
else
{
<div class="text-center">No User Sessions</div>
{
<div class="row">
<div class="col">
You do not have server-side sessions enabled.
To do so, use <i>AddServerSideSessions</i> on your IdentityServer configuration.
See the <a href="https://docs.duendesoftware.com/identityserver/v6/ui/server_side_sessions">documentation</a> for more information.
</div>
</div>
}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
20 changes: 11 additions & 9 deletions hosts/EntityFramework/Pages/ServerSideSessions/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class IndexModel : PageModel
{
private readonly ISessionManagementService _sessionManagementService;

public IndexModel(ISessionManagementService sessionManagementService)
public IndexModel(ISessionManagementService sessionManagementService = null)
{
_sessionManagementService = sessionManagementService;
}
Expand All @@ -28,15 +28,17 @@ public IndexModel(ISessionManagementService sessionManagementService)

public async Task OnGet()
{
UserSessions = await _sessionManagementService.QuerySessionsAsync(new SessionQuery
if (_sessionManagementService != null)
{
ResultsToken = Token,
RequestPriorResults = Prev == "true",
CountRequested = 10,
DisplayName = Filter,
SessionId = Filter,
SubjectId = Filter,
});
UserSessions = await _sessionManagementService.QuerySessionsAsync(new SessionQuery
{
ResultsToken = Token,
RequestPriorResults = Prev == "true",
DisplayName = Filter,
SessionId = Filter,
SubjectId = Filter,
});
}
}

[BindProperty]
Expand Down
2 changes: 1 addition & 1 deletion hosts/main/IdentityServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static WebApplicationBuilder ConfigureIdentityServer(this WebApplicatio

options.ServerSideSessions.UserDisplayNameClaimType = JwtClaimTypes.Name;
})
.AddServerSideSessions()
//.AddServerSideSessions()
.AddInMemoryClients(Clients.Get())
.AddInMemoryIdentityResources(Resources.IdentityResources)
.AddInMemoryApiScopes(Resources.ApiScopes)
Expand Down
Loading