Skip to content

Commit b11fd1e

Browse files
committed
Preparation of First Release v 0.0.1 (Part 2)
1 parent 882ce39 commit b11fd1e

20 files changed

+516
-0
lines changed

UltimateAuth.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<Project Path="src/CodeBeam.UltimateAuth.Users/CodeBeam.UltimateAuth.Server.Users.csproj" Id="30d5db36-6dc8-46f6-9139-8b6b3d6053d5" />
1717
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials.InMemory/CodeBeam.UltimateAuth.Credentials.InMemory.csproj" Id="62ee7b1d-46ce-4f2e-985d-1e794f891b8b" />
1818
<Project Path="src/security/CodeBeam.UltimateAuth.Security.Argon2/CodeBeam.UltimateAuth.Security.Argon2.csproj" Id="6abfb7a6-ea36-42db-a843-38054dd40fd8" />
19+
<Project Path="src/sessions/CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore/CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore.csproj" Id="5b9a090d-1689-4a81-9dfa-3ba69f0bda38" />
1920
<Project Path="src/sessions/CodeBeam.UltimateAuth.Sessions.InMemory/CodeBeam.UltimateAuth.Sessions.InMemory.csproj" Id="fc9bfef0-8a89-4639-81ee-3f84f6e33816" />
2021
<Project Path="src/tokens/CodeBeam.UltimateAuth.Tokens.InMemory/CodeBeam.UltimateAuth.Tokens.InMemory.csproj" Id="8220884e-4958-4b49-8c69-56ce9d2b6c6f" />
2122
</Solution>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore")]

src/CodeBeam.UltimateAuth.Core/Domain/Session/AuthSessionId.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public static bool TryCreate(string raw, out AuthSessionId sessionId)
3232
/// </summary>
3333
public string Value { get; }
3434

35+
public static AuthSessionId From(string value) => new(value);
36+
3537
/// <summary>
3638
/// Determines whether the specified <see cref="AuthSessionId"/> is equal to the current instance.
3739
/// </summary>

src/CodeBeam.UltimateAuth.Core/Domain/Session/ChainId.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public ChainId(Guid value)
2727
/// <returns>A new <see cref="ChainId"/> instance.</returns>
2828
public static ChainId New() => new ChainId(Guid.NewGuid());
2929

30+
public static ChainId From(Guid value) => new(value);
31+
3032
/// <summary>
3133
/// Determines whether the specified <see cref="ChainId"/> is equal to the current instance.
3234
/// </summary>

src/CodeBeam.UltimateAuth.Core/Domain/Session/DeviceInfo.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
/// </summary>
88
public sealed class DeviceInfo
99
{
10+
// TODO: Implement DeviceId and makes it first-class citizen in security policies.
1011
/// <summary>
1112
/// Gets the unique identifier for the device.
13+
/// No session should be created without a device id.
1214
/// </summary>
1315
public string DeviceId { get; init; } = default!;
1416

@@ -72,6 +74,17 @@ public sealed class DeviceInfo
7274
IsTrusted = null
7375
};
7476

77+
// TODO: Empty may not be good approach, make strict security here
78+
public static DeviceInfo Empty { get; } = new()
79+
{
80+
DeviceId = "",
81+
Platform = null,
82+
Browser = null,
83+
IpAddress = null,
84+
UserAgent = null,
85+
IsTrusted = null
86+
};
87+
7588
/// <summary>
7689
/// Determines whether the current device information matches the specified device information based on device
7790
/// identifiers.

src/CodeBeam.UltimateAuth.Core/Domain/Session/ISessionChain.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public interface ISessionChain<TUserId>
1212
/// </summary>
1313
ChainId ChainId { get; }
1414

15+
string? TenantId { get; }
16+
1517
/// <summary>
1618
/// Gets the identifier of the user who owns this chain.
1719
/// Each chain represents one device/login family for this user.

src/CodeBeam.UltimateAuth.Core/Domain/Session/UAuthSession.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,38 @@ public ISession<TUserId> Revoke(DateTimeOffset at)
136136
);
137137
}
138138

139+
internal static UAuthSession<TUserId> FromProjection(
140+
AuthSessionId sessionId,
141+
string? tenantId,
142+
TUserId userId,
143+
ChainId chainId,
144+
DateTimeOffset createdAt,
145+
DateTimeOffset expiresAt,
146+
DateTimeOffset? lastSeenAt,
147+
bool isRevoked,
148+
DateTimeOffset? revokedAt,
149+
long securityVersionAtCreation,
150+
DeviceInfo device,
151+
ClaimsSnapshot claims,
152+
SessionMetadata metadata)
153+
{
154+
return new UAuthSession<TUserId>(
155+
sessionId,
156+
tenantId,
157+
userId,
158+
chainId,
159+
createdAt,
160+
expiresAt,
161+
lastSeenAt,
162+
isRevoked,
163+
revokedAt,
164+
securityVersionAtCreation,
165+
device,
166+
claims,
167+
metadata
168+
);
169+
}
170+
139171
public SessionState GetState(DateTimeOffset at)
140172
{
141173
if (IsRevoked) return SessionState.Revoked;

src/CodeBeam.UltimateAuth.Core/Domain/Session/UAuthSessionChain.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,29 @@ public ISessionChain<TUserId> Revoke(DateTimeOffset at)
108108
);
109109
}
110110

111+
internal static UAuthSessionChain<TUserId> FromProjection(
112+
ChainId chainId,
113+
string? tenantId,
114+
TUserId userId,
115+
int rotationCount,
116+
long securityVersionAtCreation,
117+
ClaimsSnapshot claimsSnapshot,
118+
AuthSessionId? activeSessionId,
119+
bool isRevoked,
120+
DateTimeOffset? revokedAt)
121+
{
122+
return new UAuthSessionChain<TUserId>(
123+
chainId,
124+
tenantId,
125+
userId,
126+
rotationCount,
127+
securityVersionAtCreation,
128+
claimsSnapshot,
129+
activeSessionId,
130+
isRevoked,
131+
revokedAt
132+
);
133+
}
134+
111135
}
112136
}

src/CodeBeam.UltimateAuth.Core/Domain/Session/UAuthSessionRoot.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,26 @@ public ISessionRoot<TUserId> AttachChain(ISessionChain<TUserId> chain, DateTimeO
7676
);
7777
}
7878

79+
internal static UAuthSessionRoot<TUserId> FromProjection(
80+
string? tenantId,
81+
TUserId userId,
82+
bool isRevoked,
83+
DateTimeOffset? revokedAt,
84+
long securityVersion,
85+
IReadOnlyList<ISessionChain<TUserId>> chains,
86+
DateTimeOffset lastUpdatedAt)
87+
{
88+
return new UAuthSessionRoot<TUserId>(
89+
tenantId,
90+
userId,
91+
isRevoked,
92+
revokedAt,
93+
securityVersion,
94+
chains,
95+
lastUpdatedAt
96+
);
97+
}
98+
99+
79100
}
80101
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
8+
<NoWarn>$(NoWarn);1591</NoWarn>
9+
</PropertyGroup>
10+
11+
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
12+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.22" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.22" />
14+
</ItemGroup>
15+
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
16+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.11" />
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.11" />
18+
</ItemGroup>
19+
<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
20+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.1" />
21+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.1" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="..\..\CodeBeam.UltimateAuth.Core\CodeBeam.UltimateAuth.Core.csproj" />
26+
</ItemGroup>
27+
28+
</Project>

0 commit comments

Comments
 (0)