Skip to content

Commit abe186e

Browse files
authored
EFCore Store Implementation (#23)
* EFCore Store Implementation * Completed EFCore Session Store * Completed EFCore Token Store * Completed EFCore User Store * Completed EFCore Credential Store * Completed EFCore Authorization Store
1 parent 5207c2b commit abe186e

File tree

129 files changed

+3515
-957
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+3515
-957
lines changed

UltimateAuth.slnx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</Folder>
1515
<Project Path="src/authentication/CodeBeam.UltimateAuth.Authentication.InMemory/CodeBeam.UltimateAuth.Authentication.InMemory.csproj" Id="bd87e254-0565-4fc5-950d-ee5bbb416079" />
1616
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.Contracts/CodeBeam.UltimateAuth.Authorization.Contracts.csproj" Id="40a23002-f885-42a8-bdd9-fd962ab28742" />
17+
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore/CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore.csproj" Id="8572d1e8-db32-42a1-b61c-e8805e59c019" />
1718
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.InMemory/CodeBeam.UltimateAuth.Authorization.InMemory.csproj" Id="a1e6d007-bdc0-4574-b549-ec863757edd3" />
1819
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.Reference/CodeBeam.UltimateAuth.Authorization.Reference.csproj" Id="84b784d0-bb48-406a-a0d1-c600da667597" />
1920
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization/CodeBeam.UltimateAuth.Authorization.csproj" Id="28b1d647-fb0b-4cc3-8503-2680c4a9b28f" />
@@ -26,13 +27,15 @@
2627
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials.InMemory/CodeBeam.UltimateAuth.Credentials.InMemory.csproj" Id="62ee7b1d-46ce-4f2e-985d-1e794f891b8b" />
2728
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials.Reference/CodeBeam.UltimateAuth.Credentials.Reference.csproj" Id="ca03a140-f3dc-4a21-9b7d-895a3b10808b" />
2829
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials/CodeBeam.UltimateAuth.Credentials.csproj" Id="2281c3b5-1d60-4542-a673-553f96eed25b" />
30+
<Project Path="src/persistence/CodeBeam.UltimateAuth.EntityFrameworkCore.Abstractions/CodeBeam.UltimateAuth.EntityFrameworkCore.Abstractions.csproj" Id="8867767d-bd1b-4d51-ac3f-0979038165c9" />
2931
<Project Path="src/policies/CodeBeam.UltimateAuth.Policies/CodeBeam.UltimateAuth.Policies.csproj" Id="b37c337f-2446-4f54-8684-b72fa83ac444" />
3032
<Project Path="src/security/CodeBeam.UltimateAuth.Security.Argon2/CodeBeam.UltimateAuth.Security.Argon2.csproj" Id="6abfb7a6-ea36-42db-a843-38054dd40fd8" />
3133
<Project Path="src/sessions/CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore/CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore.csproj" Id="5b9a090d-1689-4a81-9dfa-3ba69f0bda38" />
3234
<Project Path="src/sessions/CodeBeam.UltimateAuth.Sessions.InMemory/CodeBeam.UltimateAuth.Sessions.InMemory.csproj" Id="fc9bfef0-8a89-4639-81ee-3f84f6e33816" />
3335
<Project Path="src/tokens/CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore/CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore.csproj" Id="6eb14b32-0b56-460f-a2b2-f95d28bad625" />
3436
<Project Path="src/tokens/CodeBeam.UltimateAuth.Tokens.InMemory/CodeBeam.UltimateAuth.Tokens.InMemory.csproj" Id="8220884e-4958-4b49-8c69-56ce9d2b6c6f" />
3537
<Project Path="src/users/CodeBeam.UltimateAuth.Users.Contracts/CodeBeam.UltimateAuth.Users.Contracts.csproj" Id="3a04f065-8f9d-46b3-9726-1febffe6d46f" />
38+
<Project Path="src/users/CodeBeam.UltimateAuth.Users.EntityFrameworkCore/CodeBeam.UltimateAuth.Users.EntityFrameworkCore.csproj" Id="a8febfee-0cfe-4e8c-8dcb-8703c35dd77b" />
3639
<Project Path="src/users/CodeBeam.UltimateAuth.Users.InMemory/CodeBeam.UltimateAuth.Users.InMemory.csproj" Id="7ce3df22-4773-4b9b-afd0-8ba506e0f9de" />
3740
<Project Path="src/users/CodeBeam.UltimateAuth.Users.Reference/CodeBeam.UltimateAuth.Users.Reference.csproj" Id="601176dd-b760-4b6f-9cc7-c618134ae178" />
3841
<Project Path="src/users/CodeBeam.UltimateAuth.Users/CodeBeam.UltimateAuth.Users.csproj" Id="30d5db36-6dc8-46f6-9139-8b6b3d6053d5" />
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
using CodeBeam.UltimateAuth.Core.Domain;
2-
using CodeBeam.UltimateAuth.Core.MultiTenancy;
32

43
namespace CodeBeam.UltimateAuth.Core.Abstractions;
54

6-
/// <summary>
7-
/// Low-level persistence abstraction for refresh tokens.
8-
/// NO validation logic. NO business rules.
9-
/// </summary>
105
public interface IRefreshTokenStore
116
{
12-
Task StoreAsync(TenantKey tenant, StoredRefreshToken token, CancellationToken ct = default);
7+
Task ExecuteAsync(Func<CancellationToken, Task> action, CancellationToken ct = default);
138

14-
Task<StoredRefreshToken?> FindByHashAsync(TenantKey tenant, string tokenHash, CancellationToken ct = default);
9+
Task<TResult> ExecuteAsync<TResult>(Func<CancellationToken, Task<TResult>> action, CancellationToken ct = default);
1510

16-
Task RevokeAsync(TenantKey tenant, string tokenHash, DateTimeOffset revokedAt, string? replacedByTokenHash = null, CancellationToken ct = default);
11+
Task StoreAsync(RefreshToken token, CancellationToken ct = default);
1712

18-
Task RevokeBySessionAsync(TenantKey tenant, AuthSessionId sessionId, DateTimeOffset revokedAt, CancellationToken ct = default);
13+
Task<RefreshToken?> FindByHashAsync(string tokenHash, CancellationToken ct = default);
1914

20-
Task RevokeByChainAsync(TenantKey tenant, SessionChainId chainId, DateTimeOffset revokedAt, CancellationToken ct = default);
15+
Task RevokeAsync(string tokenHash, DateTimeOffset revokedAt, string? replacedByTokenHash = null, CancellationToken ct = default);
2116

22-
Task RevokeAllForUserAsync(TenantKey tenant, UserKey userKey, DateTimeOffset revokedAt, CancellationToken ct = default);
17+
Task RevokeBySessionAsync(AuthSessionId sessionId, DateTimeOffset revokedAt, CancellationToken ct = default);
18+
19+
Task RevokeByChainAsync(SessionChainId chainId, DateTimeOffset revokedAt, CancellationToken ct = default);
20+
21+
Task RevokeAllForUserAsync(UserKey userKey, DateTimeOffset revokedAt, CancellationToken ct = default);
2322
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using CodeBeam.UltimateAuth.Core.MultiTenancy;
2+
3+
namespace CodeBeam.UltimateAuth.Core.Abstractions;
4+
5+
public interface IRefreshTokenStoreFactory
6+
{
7+
IRefreshTokenStore Create(TenantKey tenant);
8+
}

src/CodeBeam.UltimateAuth.Core/AssemblyVisibility.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Server")]
44
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore")]
5+
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore")]
6+
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Users.EntityFrameworkCore")]
7+
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Credentials.EntityFrameworkCore")]
8+
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore")]
59
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Tests.Unit")]

src/CodeBeam.UltimateAuth.Core/Contracts/Authority/AccessContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CodeBeam.UltimateAuth.Core.Domain;
2+
using CodeBeam.UltimateAuth.Core.Errors;
23
using CodeBeam.UltimateAuth.Core.MultiTenancy;
34
using System.Collections;
45

@@ -29,7 +30,7 @@ public sealed class AccessContext
2930
public UserKey GetTargetUserKey()
3031
{
3132
if (TargetUserKey is not UserKey targetUserKey)
32-
throw new InvalidOperationException("Target user is not found.");
33+
throw new UAuthNotFoundException("Target user is not found.");
3334

3435
return targetUserKey;
3536
}

src/CodeBeam.UltimateAuth.Core/Contracts/Login/LoginResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public sealed record LoginResult
77
public LoginStatus Status { get; init; }
88
public AuthSessionId? SessionId { get; init; }
99
public AccessToken? AccessToken { get; init; }
10-
public RefreshToken? RefreshToken { get; init; }
10+
public RefreshTokenInfo? RefreshToken { get; init; }
1111
public LoginContinuation? Continuation { get; init; }
1212
public AuthFailureReason? FailureReason { get; init; }
1313
public DateTimeOffset? LockoutUntilUtc { get; init; }

src/CodeBeam.UltimateAuth.Core/Contracts/Refresh/RefreshFlowResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public sealed class RefreshFlowResult
99

1010
public AuthSessionId? SessionId { get; init; }
1111
public AccessToken? AccessToken { get; init; }
12-
public RefreshToken? RefreshToken { get; init; }
12+
public RefreshTokenInfo? RefreshToken { get; init; }
1313

1414
public static RefreshFlowResult ReauthRequired()
1515
{
@@ -24,7 +24,7 @@ public static RefreshFlowResult Success(
2424
RefreshOutcome outcome,
2525
AuthSessionId? sessionId = null,
2626
AccessToken? accessToken = null,
27-
RefreshToken? refreshToken = null)
27+
RefreshTokenInfo? refreshToken = null)
2828
{
2929
return new RefreshFlowResult
3030
{

src/CodeBeam.UltimateAuth.Core/Contracts/Token/AuthTokens.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ public sealed record AuthTokens
1212
/// </summary>
1313
public AccessToken AccessToken { get; init; } = default!;
1414

15-
public RefreshToken? RefreshToken { get; init; }
15+
public RefreshTokenInfo? RefreshToken { get; init; }
1616
}

src/CodeBeam.UltimateAuth.Core/Contracts/Token/RefreshToken.cs renamed to src/CodeBeam.UltimateAuth.Core/Contracts/Token/RefreshTokenInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// Transport model for refresh token. Returned to client once upon creation.
55
/// </summary>
6-
public sealed class RefreshToken
6+
public sealed class RefreshTokenInfo
77
{
88
/// <summary>
99
/// Plain refresh token value (returned to client once).

src/CodeBeam.UltimateAuth.Core/Contracts/Token/RefreshTokenRotationResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ public sealed record RefreshTokenRotationResult
1010

1111
public AuthSessionId? SessionId { get; init; }
1212
public AccessToken? AccessToken { get; init; }
13-
public RefreshToken? RefreshToken { get; init; }
13+
public RefreshTokenInfo? RefreshToken { get; init; }
1414

1515
private RefreshTokenRotationResult() { }
1616

1717
public static RefreshTokenRotationResult Failed() => new() { IsSuccess = false, ReauthRequired = true };
1818

1919
public static RefreshTokenRotationResult Success(
2020
AccessToken accessToken,
21-
RefreshToken refreshToken)
21+
RefreshTokenInfo refreshToken)
2222
=> new()
2323
{
2424
IsSuccess = true,

0 commit comments

Comments
 (0)