Skip to content

feat: implement storage of session in database - #52

Open
jhbritton-RSK wants to merge 14 commits into
server-side-sessionsfrom
feat/35-session-store
Open

feat: implement storage of session in database#52
jhbritton-RSK wants to merge 14 commits into
server-side-sessionsfrom
feat/35-session-store

Conversation

@jhbritton-RSK

Copy link
Copy Markdown
Collaborator

Description

Implemented initial storage of session in database following the existing db schema created for compatibility.

  • Addition of an implementation of ITicketStore to tie into asp.net session storage
  • Implementation of an EF core storage class for IIdentityServerServerSideSessionStore interface.
  • Extension method for configuring server side sessions

Type of change

  • Bug fix
  • Feature
  • Refactoring
  • Documentation
  • Other

Does this PR introduce a breaking change?

  • Yes
  • No

Testing

Describe how the change has been tested. New code should be covered by appropriate unit and/or integration tests.

LLM Usage

Used for guidance on setting up integration tests, and understanding more about how the sessions work in the existing IdentityServer4 codebase.

Other context

n/a

@jhbritton-RSK jhbritton-RSK changed the title Feat/35 session store feat: implement storage of session in database Jul 30, 2026
@jhbritton-RSK
jhbritton-RSK force-pushed the feat/35-session-store branch from 3248415 to 2426413 Compare July 30, 2026 12:26
<ProjectReference Include="..\..\src\Open.IdentityServer.csproj"/>
</ItemGroup>

<ItemGroup>

@patchandthat patchandthat Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the MockLogger required in this assembly? Does TestLogger.Create<T> not suffice?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this for a mock logger I could validate logs were made. TestLogger is used in may places so wanted avoid touching it. I also shared between two test projects, might be better to spin-up a shared tests project for things like that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing unit tests for these mappers

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional class lacks any unit tests, but can you create one and add a test covering this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/// <param name="ticketStore">instance of ITicketStore to use</param>
/// <param name="idsOptions">Open.IdentityServer options</param>
/// <param name="authOptions">Authentication options</param>
public class PostConfigureSessionStoreCookieAuthOptions(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like something we should have a test covering.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit tests on this please

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests here please

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


if (existingSession == null)
{
logger.LogInformation("failed renewing '{SessionKey}' session in database, session with key doesn't exists", key);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: exists shouldn't be plural

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this should be log warning not information

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


string? subjectId = ticket.Principal.GetSubjectId();
string? sessionId = ticket.Properties.GetSessionId();
trace?.AddTag(TelemetryConstants.TagConstants.Subject, subjectId);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be putting subject and session id in the tags of the telemetry. The success or failure is enough for telemetry.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public Task RemoveAsync(string key)
{
using ITrace? trace = telemetry.Trace(TelemetryConstants.TraceCategories.Stores, this);
trace?.AddTag(TelemetryConstants.TagConstants.Key, key);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't put the key in the tags, I can't see the use of this and it will create noise

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

///
/// </summary>
/// <param name="seedData"></param>
public InMemorySessionStore(IDictionary<string, IdentityServerServerSideSessions> seedData): this()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeding data for sessions? Is this for unit testing?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following original pattern of other stores. But doesn't really make sense for server side sessions other than for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants