Skip to content

Commit 7ee3e21

Browse files
committed
Login Flow & Code Improvements
1 parent f093620 commit 7ee3e21

71 files changed

Lines changed: 1329 additions & 431 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace CodeBeam.UltimateAuth.Core.Abstractions
2+
{
3+
/// <summary>
4+
/// Provides an abstracted time source for the system.
5+
/// Used to improve testability and ensure consistent time handling.
6+
/// </summary>
7+
public interface IClock
8+
{
9+
DateTime UtcNow { get; }
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using CodeBeam.UltimateAuth.Core.Domain;
2+
3+
namespace CodeBeam.UltimateAuth.Core.Abstractions
4+
{
5+
public interface IUserAuthenticator<TUserId>
6+
{
7+
Task<UserAuthenticationResult<TUserId>> AuthenticateAsync(
8+
string? tenantId,
9+
string identifier,
10+
string secret,
11+
CancellationToken cancellationToken = default);
12+
}
13+
}

src/CodeBeam.UltimateAuth.Core/Abstractions/Issuers/ISessionIssuer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ namespace CodeBeam.UltimateAuth.Core.Abstractions
88
/// </summary>
99
public interface ISessionIssuer<TUserId>
1010
{
11-
Task<IssuedSession<TUserId>> IssueAsync(SessionIssueContext<TUserId> context, UAuthSessionChain<TUserId> chain, CancellationToken cancellationToken = default);
11+
Task<IssuedSession<TUserId>> IssueAsync(AuthenticatedSessionContext<TUserId> context, ISessionChain<TUserId> chain, CancellationToken cancellationToken = default);
1212
}
1313
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CodeBeam.UltimateAuth.Core.Contexts;
2+
using CodeBeam.UltimateAuth.Core.Models;
23

34
namespace CodeBeam.UltimateAuth.Core.Abstractions
45
{
@@ -8,7 +9,7 @@ namespace CodeBeam.UltimateAuth.Core.Abstractions
89
/// </summary>
910
public interface ITokenIssuer
1011
{
11-
Task<IssuedAccessToken> IssueAccessTokenAsync(TokenIssueContext context, CancellationToken cancellationToken = default);
12-
Task<IssuedRefreshToken?> IssueRefreshTokenAsync(TokenIssueContext context, CancellationToken cancellationToken = default);
12+
Task<AccessToken> IssueAccessTokenAsync(TokenIssuerContext context, CancellationToken cancellationToken = default);
13+
Task<RefreshToken?> IssueRefreshTokenAsync(TokenIssuerContext context, CancellationToken cancellationToken = default);
1314
}
1415
}

src/CodeBeam.UltimateAuth.Core/Abstractions/Services/IUAuthSessionService.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodeBeam.UltimateAuth.Core.Domain;
1+
using CodeBeam.UltimateAuth.Core.Contexts;
2+
using CodeBeam.UltimateAuth.Core.Domain;
23
using CodeBeam.UltimateAuth.Core.Models;
34

45
namespace CodeBeam.UltimateAuth.Core.Abstractions
@@ -38,9 +39,25 @@ Task RevokeChainAsync(
3839
ChainId chainId,
3940
DateTime at);
4041

42+
Task<ChainId?> ResolveChainIdAsync(
43+
string? tenantId,
44+
AuthSessionId sessionId);
45+
46+
Task RevokeAllChainsAsync(
47+
string? tenantId,
48+
TUserId userId,
49+
ChainId? exceptChainId,
50+
DateTime at);
51+
52+
// Hard revoke - admin
4153
Task RevokeRootAsync(
4254
string? tenantId,
4355
TUserId userId,
4456
DateTime at);
57+
58+
Task<IssuedSession<TUserId>> IssueSessionAfterAuthenticationAsync(
59+
string? tenantId,
60+
AuthenticatedSessionContext<TUserId> context,
61+
CancellationToken cancellationToken = default);
4562
}
4663
}

src/CodeBeam.UltimateAuth.Core/Abstractions/Services/IUAuthTokenService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ public interface IUAuthTokenService<TUserId>
1212
/// Issues access (and optionally refresh) tokens
1313
/// for a validated session.
1414
/// </summary>
15-
Task<TokenIssueResult> IssueAsync(
15+
Task<AuthTokens> CreateTokensAsync(
1616
TokenIssueContext<TUserId> context,
1717
CancellationToken cancellationToken = default);
1818

1919
/// <summary>
2020
/// Refreshes tokens using a refresh token.
2121
/// </summary>
22-
Task<TokenIssueResult> RefreshAsync(
22+
Task<AuthTokens> RefreshAsync(
2323
TokenRefreshContext context,
2424
CancellationToken cancellationToken = default);
2525

src/CodeBeam.UltimateAuth.Core/Abstractions/Stores/ISessionStoreKernel.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ public interface ISessionStoreKernel<TUserId>
5656
/// <param name="chain">The chain to save.</param>
5757
Task SaveChainAsync(string? tenantId, ISessionChain<TUserId> chain);
5858

59-
/// <summary>
60-
/// Updates an existing session chain, typically after session rotation or revocation. Implementations must preserve atomicity.
61-
/// </summary>
62-
/// <param name="tenantId">The tenant identifier, or <c>null</c>.</param>
63-
/// <param name="chain">The updated session chain.</param>
64-
Task UpdateChainAsync(string? tenantId, ISessionChain<TUserId> chain);
65-
6659
/// <summary>
6760
/// Marks the entire session chain as revoked, invalidating all associated sessions for the device or app family.
6861
/// </summary>
@@ -135,6 +128,11 @@ public interface ISessionStoreKernel<TUserId>
135128
/// <param name="sessionId">The session identifier.</param>
136129
/// <returns>The chain identifier or <c>null</c>.</returns>
137130
Task<ChainId?> GetChainIdBySessionAsync(string? tenantId, AuthSessionId sessionId);
138-
}
139131

132+
/// <summary>
133+
/// Executes multiple store operations as a single atomic unit.
134+
/// Implementations must ensure transactional consistency where supported.
135+
/// </summary>
136+
Task ExecuteAsync(Func<Task> action);
137+
}
140138
}

src/CodeBeam.UltimateAuth.Core/Abstractions/Stores/IUAuthUserStore.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@ namespace CodeBeam.UltimateAuth.Core.Abstractions
99
/// </summary>
1010
public interface IUAuthUserStore<TUserId>
1111
{
12-
/// <summary>
13-
/// Retrieves a user by identifier. Returns <c>null</c> if no such user exists.
14-
/// </summary>
15-
/// <param name="userId">The identifier of the user.</param>
16-
/// <returns>The user instance or <c>null</c> if not found.</returns>
17-
Task<IUser<TUserId>?> FindByIdAsync(TUserId userId);
12+
Task<IUser<TUserId>?> FindByIdAsync(string? tenantId, TUserId userId, CancellationToken token = default);
1813

19-
Task<UserRecord<TUserId>?> FindByUsernameAsync(
14+
Task<UserRecord<TUserId>?> FindByUsernameAsync(string? tenantId,
2015
string username,
2116
CancellationToken ct = default);
2217

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using CodeBeam.UltimateAuth.Core.Domain;
2+
3+
namespace CodeBeam.UltimateAuth.Core.Contexts
4+
{
5+
/// <summary>
6+
/// Represents the context in which a session is issued
7+
/// (login, refresh, reauthentication).
8+
/// </summary>
9+
public sealed class AuthenticatedSessionContext<TUserId>
10+
{
11+
public string? TenantId { get; init; }
12+
public required TUserId UserId { get; init; }
13+
public DeviceInfo DeviceInfo { get; init; }
14+
public DateTime Now { get; init; }
15+
public ClaimsSnapshot? Claims { get; init; }
16+
public SessionMetadata Metadata { get; init; }
17+
18+
/// <summary>
19+
/// Optional chain identifier.
20+
/// If null, a new chain will be created.
21+
/// If provided, session will be issued under the existing chain.
22+
/// </summary>
23+
public ChainId? ChainId { get; init; }
24+
25+
/// <summary>
26+
/// Indicates that authentication has already been completed.
27+
/// This context MUST NOT be constructed from raw credentials.
28+
/// </summary>
29+
public bool IsAuthenticated { get; init; } = true;
30+
}
31+
}

src/CodeBeam.UltimateAuth.Core/Contexts/Issued/IssuedAccessToken.cs renamed to src/CodeBeam.UltimateAuth.Core/Contexts/Issued/AccessToken.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// Represents an issued access token (JWT or opaque).
55
/// </summary>
6-
public sealed class IssuedAccessToken
6+
public sealed class AccessToken
77
{
88
/// <summary>
99
/// The actual token value sent to the client.
@@ -26,5 +26,7 @@ public sealed class IssuedAccessToken
2626
/// Optional session id this token is bound to (Hybrid / SemiHybrid).
2727
/// </summary>
2828
public string? SessionId { get; init; }
29+
30+
public string? Scope { get; init; }
2931
}
3032
}

0 commit comments

Comments
 (0)