Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Reflection;

namespace Open.IdentityServer.UnitTests;
namespace Open.IdentityServer.Test.Utilities;

public class LocalTimeZoneInfoMocker: IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
9 changes: 9 additions & 0 deletions Open.IdentityServer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7A351D3D
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Open.IdentityServer.Storage.UnitTests", "src\Storage\tests\Open.IdentityServer.Storage.UnitTests\Open.IdentityServer.Storage.UnitTests.csproj", "{FF1944C8-2516-4197-9B63-8BB3581882B3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{36985CF3-7E79-4BF4-91FD-3E9195A0FCEA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Open.IdentityServer.Test.Utilities", "Open.IdentityServer.Test.Utilities\Open.IdentityServer.Test.Utilities.csproj", "{F0AD47D4-F27B-4265-B1B9-B2346824CBE4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -109,6 +113,7 @@ Global
{C459AC33-FD11-402E-8058-F76DD940190D} = {78510D3C-6BE1-4017-8AD4-CC905D58D788}
{7A351D3D-4AC7-4662-8BF3-8F42D6097F87} = {7C740022-8283-4021-8E72-3F2847949309}
{FF1944C8-2516-4197-9B63-8BB3581882B3} = {7A351D3D-4AC7-4662-8BF3-8F42D6097F87}
{F0AD47D4-F27B-4265-B1B9-B2346824CBE4} = {36985CF3-7E79-4BF4-91FD-3E9195A0FCEA}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A2D626B8-1532-4E35-B9F2-4246C838D192}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -183,5 +188,9 @@ Global
{FF1944C8-2516-4197-9B63-8BB3581882B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF1944C8-2516-4197-9B63-8BB3581882B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF1944C8-2516-4197-9B63-8BB3581882B3}.Release|Any CPU.Build.0 = Release|Any CPU
{F0AD47D4-F27B-4265-B1B9-B2346824CBE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0AD47D4-F27B-4265-B1B9-B2346824CBE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0AD47D4-F27B-4265-B1B9-B2346824CBE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0AD47D4-F27B-4265-B1B9-B2346824CBE4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public class OperationalStoreOptions: StoreOptions
/// </value>
public TableConfiguration DeviceFlowCodes { get; set; } = new TableConfiguration("DeviceCodes");

/// <summary>
/// Gets or sets the server-side sessions table configuration.
/// </summary>
/// <value>
/// The server-side sessions' config.
/// </value>
public TableConfiguration ServerSideSessions { get; set; } = new("ServerSideSessions");

/// <summary>
/// Gets or sets a value indicating whether stale entries will be automatically cleaned up from the database.
/// This is implemented by periodically connecting to the database (according to the TokenCleanupInterval) from the hosting application.
Expand Down Expand Up @@ -61,14 +69,6 @@ public class OperationalStoreOptions: StoreOptions
/// </value>
public TableConfiguration Keys { get; set; } = new("Keys");

/// <summary>
/// Gets or sets the server-side sessions table configuration.
/// </summary>
/// <value>
/// The server-side sessions' config.
/// </value>
public TableConfiguration ServerSideSessions { get; set; } = new("ServerSideSessions");

/// <summary>
/// Gets or sets the pushed authorization requests table configuration.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Open.IdentityServer.EntityFramework.Stores;
public class IdentityServerServerSideSessionStore(
IPersistedGrantDbContext dbContext,
ITelemetryService telemetry,
TimeProvider timeProvider,
ILogger<IdentityServerServerSideSessionStore> logger) : IIdentityServerServerSideSessionStore
{
/// <inheritdoc />
Expand Down Expand Up @@ -138,4 +139,23 @@ public async Task<IEnumerable<IdentityServerServerSideSessions>> FilterSessions(
.ToListAsync())
.Select(x => x.ToModel());
}

/// <inheritdoc />
public async Task<IEnumerable<IdentityServerServerSideSessions>> GetAndRemoveExpiredSessions(int batchSize = 100)
{
using var trace = telemetry.Trace(TelemetryConstants.TraceCategories.Stores, this);

var sessions = await dbContext.ServerSideSessions
// .Where(x => x.Expires < DateTime.UtcNow)
.Where(x => x.Expires < timeProvider.GetUtcNow().UtcDateTime)
.OrderBy(x => x.Expires)
.Take(batchSize)
.ToArrayAsync();

dbContext.ServerSideSessions.RemoveRange(sessions);
await dbContext.SaveChangesAsync();

return sessions.Select(x => x.ToModel());

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.


using System;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -13,7 +12,7 @@
namespace Open.IdentityServer.EntityFramework;

/// <summary>
/// Helper to cleanup stale persisted grants and device codes.
/// Helper to clean up stale persisted grants and device codes.
/// </summary>
public class TokenCleanupService
{
Expand Down Expand Up @@ -94,8 +93,7 @@ protected virtual async Task RemoveGrantsAsync()
}
}
}



/// <summary>
/// Removes the stale device codes.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\Open.IdentityServer.Test.Utilities\Open.IdentityServer.Test.Utilities.csproj" />
<ProjectReference Include="..\..\src\Open.IdentityServer.EntityFramework.Storage.csproj"/>
</ItemGroup>

Expand All @@ -26,6 +27,7 @@
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="AwesomeAssertions"/>
<PackageReference Include="Moq"/>
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing"/>

<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite"/>
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3"/>
Expand Down
Loading