Skip to content

Commit

Permalink
Reimplemented Sessions. (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Utar94 authored Dec 20, 2024
1 parent c8231ee commit 56298f6
Show file tree
Hide file tree
Showing 23 changed files with 374 additions and 381 deletions.
File renamed without changes.
38 changes: 36 additions & 2 deletions lib/Logitar.Identity.Core/Logitar.Identity.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>Logitar.Identity.Core</Title>
<Authors>Francis Pion</Authors>
<Company>Logitar</Company>
<Product>Logitar.Identity</Product>
<Description>Exposes domain aggregates, events, entities, value objects, exceptions and services of an Identity system.</Description>
<Copyright>© 2024 Logitar All Rights Reserved.</Copyright>
<PackageIcon>logitar.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/Logitar/Identity</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<Version>0.0.0</Version>
<NeutralLanguage>en-CA</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageReleaseNotes>Rewrote the framework to include changes made to EventSourcing.</PackageReleaseNotes>
<PackageTags>logitar;net;framework;identity;domain</PackageTags>
<PackageProjectUrl>https://github.com/Logitar/Identity/tree/main/lib/Logitar.Identity.Core</PackageProjectUrl>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down Expand Up @@ -40,4 +59,19 @@
<Using Include="System.Text.Json.Serialization" />
</ItemGroup>

<ItemGroup>
<None Update="LICENSE">
<PackagePath>\</PackagePath>
<Pack>True</Pack>
</None>
<None Update="logitar.png">
<PackagePath>\</PackagePath>
<Pack>True</Pack>
</None>
<None Update="README.md">
<PackagePath>\</PackagePath>
<Pack>True</Pack>
</None>
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions lib/Logitar.Identity.Core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Logitar.Identity.Core

Exposes domain aggregates, events, entities, value objects, exceptions and services of an Identity system.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Logitar.EventSourcing;
using Logitar.Identity.Domain.Passwords;
using Logitar.Identity.Domain.Users;
using Logitar.Identity.Core.Passwords;
using Logitar.Identity.Core.Users;
using MediatR;

namespace Logitar.Identity.Domain.Sessions.Events;
namespace Logitar.Identity.Core.Sessions.Events;

/// <summary>
/// The event raised when a new session is created.
/// </summary>
public class SessionCreatedEvent : DomainEvent, INotification
public record SessionCreated : DomainEvent, INotification
{
/// <summary>
/// Gets the identifier of the user owning the session.
Expand All @@ -20,11 +20,11 @@ public class SessionCreatedEvent : DomainEvent, INotification
public Password? Secret { get; }

/// <summary>
/// Initializes a new instance of the <see cref="SessionCreatedEvent"/> class.
/// Initializes a new instance of the <see cref="SessionCreated"/> class.
/// </summary>
/// <param name="secret">The secret of the session.</param>
/// <param name="userId">The identifier of the user owning the session.</param>
public SessionCreatedEvent(Password? secret, UserId userId)
public SessionCreated(Password? secret, UserId userId)
{
Secret = secret;
UserId = userId;
Expand Down
9 changes: 9 additions & 0 deletions lib/Logitar.Identity.Core/Sessions/Events/SessionDeleted.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Logitar.EventSourcing;
using MediatR;

namespace Logitar.Identity.Core.Sessions.Events;

/// <summary>
/// The event raised when a session is deleted.
/// </summary>
public record SessionDeleted : DomainEvent, IDeleteEvent, INotification;
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using Logitar.EventSourcing;
using Logitar.Identity.Domain.Passwords;
using Logitar.Identity.Core.Passwords;
using MediatR;

namespace Logitar.Identity.Domain.Sessions.Events;
namespace Logitar.Identity.Core.Sessions.Events;

/// <summary>
/// The event raised when a session is renewed.
/// </summary>
public class SessionRenewedEvent : DomainEvent, INotification
public record SessionRenewed : DomainEvent, INotification
{
/// <summary>
/// Gets the new secret of the session.
/// </summary>
public Password Secret { get; }

/// <summary>
/// Initializes a new instance of the <see cref="SessionRenewedEvent"/> class.
/// Initializes a new instance of the <see cref="SessionRenewed"/> class.
/// </summary>
/// <param name="secret">The new secret of the session.</param>
public SessionRenewedEvent(Password secret)
public SessionRenewed(Password secret)
{
Secret = secret;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Logitar.EventSourcing;
using MediatR;

namespace Logitar.Identity.Domain.Sessions.Events;
namespace Logitar.Identity.Core.Sessions.Events;

/// <summary>
/// The event raised when an active session is signed-out.
/// </summary>
public class SessionSignedOutEvent : DomainEvent, INotification;
public record SessionSignedOut : DomainEvent, INotification;
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Logitar.EventSourcing;
using MediatR;

namespace Logitar.Identity.Domain.Sessions.Events;
namespace Logitar.Identity.Core.Sessions.Events;

/// <summary>
/// The event raised when an existing session is modified.
/// </summary>
public class SessionUpdatedEvent : DomainEvent, INotification
public record SessionUpdated : DomainEvent, INotification
{
/// <summary>
/// Gets or sets the custom attribute modifications of the session.
/// </summary>
public Dictionary<string, string?> CustomAttributes { get; init; } = [];
public Dictionary<Identifier, string?> CustomAttributes { get; init; } = [];

/// <summary>
/// Gets a value indicating whether or not the session is being modified.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Logitar.Identity.Domain.Shared;

namespace Logitar.Identity.Domain.Sessions;
namespace Logitar.Identity.Core.Sessions;

/// <summary>
/// The exception raised when a session secret check fails.
Expand All @@ -10,15 +8,15 @@ public class IncorrectSessionSecretException : InvalidCredentialsException
/// <summary>
/// A generic error message for this exception.
/// </summary>
public new const string ErrorMessage = "The specified secret did not match the session.";
private const string ErrorMessage = "The specified secret did not match the session.";

/// <summary>
/// Gets or sets the identifier of the session.
/// </summary>
public SessionId SessionId
public string SessionId
{
get => new((string)Data[nameof(SessionId)]!);
private set => Data[nameof(SessionId)] = value.Value;
get => (string)Data[nameof(SessionId)]!;
private set => Data[nameof(SessionId)] = value;
}
/// <summary>
/// Gets or sets the attempted secret.
Expand All @@ -34,15 +32,21 @@ public string AttemptedSecret
/// </summary>
/// <param name="attemptedSecret">The attempted secret.</param>
/// <param name="session">The session.</param>
public IncorrectSessionSecretException(SessionAggregate session, string attemptedSecret)
public IncorrectSessionSecretException(Session session, string attemptedSecret)
: base(BuildMessage(session, attemptedSecret))
{
SessionId = session.Id;
SessionId = session.Id.Value;
AttemptedSecret = attemptedSecret;
}

private static string BuildMessage(SessionAggregate session, string attemptedSecret) => new ErrorMessageBuilder(ErrorMessage)
/// <summary>
/// Builds the exception message.
/// </summary>
/// <param name="attemptedSecret">The attempted secret.</param>
/// <param name="session">The session.</param>
/// <returns>The exception message.</returns>
private static string BuildMessage(Session session, string attemptedSecret) => new ErrorMessageBuilder(ErrorMessage)
.AddData(nameof(AttemptedSecret), attemptedSecret)
.AddData(nameof(SessionId), session.Id.Value)
.AddData(nameof(SessionId), session.Id)
.Build();
}
Loading

0 comments on commit 56298f6

Please sign in to comment.