Skip to content

Commit b3123c9

Browse files
committed
Completed EFCore Token Store
1 parent da040c2 commit b3123c9

File tree

55 files changed

+868
-360
lines changed

Some content is hidden

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

55 files changed

+868
-360
lines changed

UltimateAuth.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials.InMemory/CodeBeam.UltimateAuth.Credentials.InMemory.csproj" Id="62ee7b1d-46ce-4f2e-985d-1e794f891b8b" />
2727
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials.Reference/CodeBeam.UltimateAuth.Credentials.Reference.csproj" Id="ca03a140-f3dc-4a21-9b7d-895a3b10808b" />
2828
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials/CodeBeam.UltimateAuth.Credentials.csproj" Id="2281c3b5-1d60-4542-a673-553f96eed25b" />
29+
<Project Path="src/persistence/CodeBeam.UltimateAuth.EntityFrameworkCore.Abstractions/CodeBeam.UltimateAuth.EntityFrameworkCore.Abstractions.csproj" Id="8867767d-bd1b-4d51-ac3f-0979038165c9" />
2930
<Project Path="src/policies/CodeBeam.UltimateAuth.Policies/CodeBeam.UltimateAuth.Policies.csproj" Id="b37c337f-2446-4f54-8684-b72fa83ac444" />
3031
<Project Path="src/security/CodeBeam.UltimateAuth.Security.Argon2/CodeBeam.UltimateAuth.Security.Argon2.csproj" Id="6abfb7a6-ea36-42db-a843-38054dd40fd8" />
3132
<Project Path="src/sessions/CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore/CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore.csproj" Id="5b9a090d-1689-4a81-9dfa-3ba69f0bda38" />
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Server")]
44
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore")]
5+
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore")]
56
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Tests.Unit")]

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,

src/CodeBeam.UltimateAuth.Core/Domain/Device/DeviceContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public static DeviceContext Anonymous()
3838

3939
public static DeviceContext Create(
4040
DeviceId deviceId,
41-
string? deviceType,
42-
string? platform,
43-
string? operatingSystem,
44-
string? browser,
45-
string? ipAddress)
41+
string? deviceType = null,
42+
string? platform = null,
43+
string? operatingSystem = null,
44+
string? browser = null,
45+
string? ipAddress = null)
4646
{
4747
return new DeviceContext(
4848
deviceId,

0 commit comments

Comments
 (0)