Skip to content

Commit bd2e09a

Browse files
committed
Add All Required Projects
1 parent df96dbf commit bd2e09a

File tree

15 files changed

+283
-100
lines changed

15 files changed

+283
-100
lines changed

UltimateAuth.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<Project Path="src/CodeBeam.UltimateAuth.Core/CodeBeam.UltimateAuth.Core.csproj" />
88
<Project Path="src/CodeBeam.UltimateAuth.Server/CodeBeam.UltimateAuth.Server.csproj" Id="0a8cdd12-a8c4-4530-87e8-ae778c46322b" />
99
<Project Path="src/CodeBeam.UltimateAuth.Users/CodeBeam.UltimateAuth.Server.Users.csproj" Id="30d5db36-6dc8-46f6-9139-8b6b3d6053d5" />
10+
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials.InMemory/CodeBeam.UltimateAuth.Credentials.InMemory.csproj" Id="62ee7b1d-46ce-4f2e-985d-1e794f891b8b" />
1011
<Project Path="src/security/CodeBeam.UltimateAuth.Security.Argon2/CodeBeam.UltimateAuth.Security.Argon2.csproj" Id="6abfb7a6-ea36-42db-a843-38054dd40fd8" />
1112
<Project Path="src/sessions/CodeBeam.UltimateAuth.Sessions.InMemory/CodeBeam.UltimateAuth.Sessions.InMemory.csproj" Id="fc9bfef0-8a89-4639-81ee-3f84f6e33816" />
1213
<Project Path="src/tokens/CodeBeam.UltimateAuth.Tokens.InMemory/CodeBeam.UltimateAuth.Tokens.InMemory.csproj" Id="8220884e-4958-4b49-8c69-56ce9d2b6c6f" />

src/CodeBeam.UltimateAuth.Core/Abstractions/Principals/IUserAuthenticator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace CodeBeam.UltimateAuth.Core.Abstractions
44
{
55
public interface IUserAuthenticator<TUserId>
66
{
7-
Task<UserAuthenticationResult<TUserId>> AuthenticateAsync(string? tenantId, string identifier, string secret, CancellationToken cancellationToken = default);
7+
Task<UserAuthenticationResult<TUserId>> AuthenticateAsync(AuthenticationContext context, CancellationToken ct = default);
88
}
99
}

src/CodeBeam.UltimateAuth.Core/Abstractions/Principals/IUserIdConverter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/// strongly typed values, string representations, and binary formats.
66
/// Implementations enable consistent storage, token serialization,
77
/// and multitenant key partitioning.
8+
/// Returned string must be stable and culture-invariant.
9+
/// Implementations must be deterministic and reversible.
810
/// </summary>
911
public interface IUserIdConverter<TUserId>
1012
{

src/CodeBeam.UltimateAuth.Core/Abstractions/Principals/IUserIdConverterResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public interface IUserIdConverterResolver
1818
/// <exception cref="InvalidOperationException">
1919
/// Thrown if no converter has been registered for the requested user ID type.
2020
/// </exception>
21-
IUserIdConverter<TUserId> GetConverter<TUserId>();
21+
IUserIdConverter<TUserId> GetConverter<TUserId>(string? purpose = null);
2222
}
2323
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
namespace CodeBeam.UltimateAuth.Core.Abstractions
44
{
55
/// <summary>
6-
/// Minimal user operations required for authentication.
7-
/// Does NOT include role or permission management.
6+
/// Defines the minimal user authentication contract expected by UltimateAuth.
7+
/// This service does not manage sessions, tokens, or transport concerns.
88
/// For user management, CodeBeam.UltimateAuth.Users package is recommended.
99
/// </summary>
1010
public interface IUAuthUserService<TUserId>
1111
{
12-
Task<TUserId> RegisterAsync(RegisterUserRequest request, CancellationToken cancellationToken = default);
13-
14-
Task DeleteAsync(TUserId userId, CancellationToken cancellationToken = default);
15-
16-
Task<bool> ValidateCredentialsAsync(ValidateCredentialsRequest request, CancellationToken cancellationToken = default);
17-
1812
Task<UserAuthenticationResult<TUserId>> AuthenticateAsync(string? tenantId, string identifier, string secret, CancellationToken cancellationToken = default);
13+
Task<bool> ValidateCredentialsAsync(ValidateCredentialsRequest request, CancellationToken cancellationToken = default);
1914
}
2015
}

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ public interface IUAuthUserStore<TUserId>
1212
{
1313
Task<IUser<TUserId>?> FindByIdAsync(string? tenantId, TUserId userId, CancellationToken token = default);
1414

15-
Task<UserRecord<TUserId>?> FindByUsernameAsync(string? tenantId,
16-
string username,
17-
CancellationToken ct = default);
15+
Task<UserRecord<TUserId>?> FindByUsernameAsync(string? tenantId, string username, CancellationToken ct = default);
1816

1917
/// <summary>
2018
/// Retrieves a user by a login credential such as username or email.
2119
/// Returns <c>null</c> if no matching user exists.
2220
/// </summary>
2321
/// <param name="login">The login value used to locate the user.</param>
2422
/// <returns>The user instance or <c>null</c> if not found.</returns>
25-
Task<IUser<TUserId>?> FindByLoginAsync(string login);
23+
Task<IUser<TUserId>?> FindByLoginAsync(string? tenantId, string login, CancellationToken token = default);
2624

2725
/// <summary>
2826
/// Returns the password hash for the specified user, if the user participates
@@ -31,15 +29,15 @@ public interface IUAuthUserStore<TUserId>
3129
/// </summary>
3230
/// <param name="userId">The user identifier.</param>
3331
/// <returns>The password hash or <c>null</c>.</returns>
34-
Task<string?> GetPasswordHashAsync(TUserId userId);
32+
Task<string?> GetPasswordHashAsync(string? tenantId, TUserId userId, CancellationToken token = default);
3533

3634
/// <summary>
3735
/// Updates the password hash for the specified user. This method is invoked by
3836
/// password management services and not by <see cref="IUAuthSessionService{TUserId}"/>.
3937
/// </summary>
4038
/// <param name="userId">The user identifier.</param>
4139
/// <param name="passwordHash">The new password hash value.</param>
42-
Task SetPasswordHashAsync(TUserId userId, string passwordHash);
40+
Task SetPasswordHashAsync(string? tenantId, TUserId userId, string passwordHash, CancellationToken token = default);
4341

4442
/// <summary>
4543
/// Retrieves the security version associated with the user.
@@ -48,25 +46,13 @@ public interface IUAuthUserStore<TUserId>
4846
/// </summary>
4947
/// <param name="userId">The user identifier.</param>
5048
/// <returns>The current security version.</returns>
51-
Task<long> GetSecurityVersionAsync(TUserId userId);
49+
Task<long> GetSecurityVersionAsync(string? tenantId, TUserId userId, CancellationToken token = default);
5250

5351
/// <summary>
5452
/// Increments the user's security version, invalidating all existing sessions.
5553
/// This is typically called after sensitive security events occur.
5654
/// </summary>
5755
/// <param name="userId">The user identifier.</param>
58-
Task IncrementSecurityVersionAsync(TUserId userId);
59-
60-
Task<bool> ExistsByUsernameAsync(
61-
string username,
62-
CancellationToken ct = default);
63-
64-
Task CreateAsync(
65-
UserRecord<TUserId> user,
66-
CancellationToken ct = default);
67-
68-
Task DeleteAsync(
69-
TUserId userId,
70-
CancellationToken ct = default);
56+
Task IncrementSecurityVersionAsync(string? tenantId, TUserId userId, CancellationToken token = default);
7157
}
7258
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace CodeBeam.UltimateAuth.Core.Contracts
2+
{
3+
public sealed record AuthenticationContext
4+
{
5+
public string? TenantId { get; init; }
6+
public string Identifier { get; init; } = default!;
7+
public string Secret { get; init; } = default!;
8+
public AuthOperation Operation { get; init; } // Login, Reauth, Validate
9+
public DeviceContext? Device { get; init; }
10+
}
11+
}
Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,29 @@
11
using CodeBeam.UltimateAuth.Core.Abstractions;
22
using CodeBeam.UltimateAuth.Core.Contracts;
3-
using CodeBeam.UltimateAuth.Core.Infrastructure;
43

54
namespace CodeBeam.UltimateAuth.Server.Users;
65

76
internal sealed class UAuthUserService<TUserId> : IUAuthUserService<TUserId>
87
{
9-
private readonly IUAuthUserStore<TUserId> _userStore;
10-
private readonly IUAuthPasswordHasher _passwordHasher;
11-
private readonly IUserIdFactory<TUserId> _userIdFactory;
128
private readonly IUserAuthenticator<TUserId> _authenticator;
139

14-
public UAuthUserService(
15-
IUAuthUserStore<TUserId> userStore,
16-
IUAuthPasswordHasher passwordHasher,
17-
IUserIdFactory<TUserId> userIdFactory,
18-
IUserAuthenticator<TUserId> authenticator)
10+
public UAuthUserService(IUserAuthenticator<TUserId> authenticator)
1911
{
20-
_userStore = userStore;
21-
_passwordHasher = passwordHasher;
22-
_userIdFactory = userIdFactory;
2312
_authenticator = authenticator;
2413
}
2514

26-
public async Task<TUserId> RegisterAsync(
27-
RegisterUserRequest request,
28-
CancellationToken ct = default)
15+
public async Task<UserAuthenticationResult<TUserId>> AuthenticateAsync(string? tenantId, string identifier, string secret, CancellationToken ct = default)
2916
{
30-
if (string.IsNullOrWhiteSpace(request.Identifier))
31-
throw new ArgumentException("Username is required.");
32-
33-
if (string.IsNullOrWhiteSpace(request.Password))
34-
throw new ArgumentException("Password is required.");
35-
36-
if (await _userStore.ExistsByUsernameAsync(request.Identifier, ct))
37-
throw new InvalidOperationException("User already exists.");
38-
39-
var hash = _passwordHasher.Hash(request.Password);
40-
41-
var userId = _userIdFactory.Create();
42-
43-
await _userStore.CreateAsync(
44-
new UserRecord<TUserId>
45-
{
46-
Id = userId,
47-
Username = request.Identifier,
48-
PasswordHash = hash,
49-
CreatedAt = DateTimeOffset.UtcNow
50-
},
51-
ct);
52-
53-
return userId;
17+
return await _authenticator.AuthenticateAsync(tenantId, identifier, secret, ct);
5418
}
5519

56-
public async Task<bool> ValidateCredentialsAsync(
57-
ValidateCredentialsRequest request,
58-
CancellationToken ct = default)
20+
// This method must not issue sessions or tokens
21+
public async Task<bool> ValidateCredentialsAsync(ValidateCredentialsRequest request, CancellationToken ct = default)
5922
{
60-
var user = await _userStore.FindByUsernameAsync(request.TenantId, request.Identifier, ct);
61-
if (user is null)
62-
return false;
63-
64-
return _passwordHasher.Verify(
65-
request.Password,
66-
user.PasswordHash);
67-
}
68-
69-
public async Task DeleteAsync(
70-
TUserId userId,
71-
CancellationToken ct = default)
72-
{
73-
await _userStore.DeleteAsync(userId, ct);
23+
24+
var result = await _authenticator.AuthenticateAsync(request.TenantId, request.Identifier, request.Password, ct);
25+
return result.Succeeded;
7426
}
7527

76-
public async Task<UserAuthenticationResult<TUserId>> AuthenticateAsync(
77-
string? tenantId,
78-
string identifier,
79-
string secret,
80-
CancellationToken cancellationToken = default)
81-
{
82-
return await _authenticator.AuthenticateAsync(
83-
tenantId,
84-
identifier,
85-
secret,
86-
cancellationToken);
87-
}
8828
}
8929

src/CodeBeam.UltimateAuth.Users/Abstractions/IUAuthUserManagementService.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
namespace CodeBeam.UltimateAuth.Server.Users
1+
using CodeBeam.UltimateAuth.Server.Users.Contracts;
2+
3+
namespace CodeBeam.UltimateAuth.Server.Users
24
{
35
/// <summary>
46
/// Administrative user management operations.
57
/// </summary>
68
public interface IUAuthUserManagementService<TUserId>
79
{
10+
Task<TUserId> RegisterAsync(RegisterUserRequest request, CancellationToken cancellationToken = default);
11+
12+
Task DeleteAsync(TUserId userId, CancellationToken cancellationToken = default);
13+
814
Task<UserDto<TUserId>> GetByIdAsync(
915
TUserId userId,
1016
CancellationToken ct = default);
@@ -24,5 +30,7 @@ Task ResetPasswordAsync(
2430
TUserId userId,
2531
ResetPasswordRequest request,
2632
CancellationToken ct = default);
33+
34+
// TODO: Change password, Update user info, etc.
2735
}
2836
}

src/CodeBeam.UltimateAuth.Core/Contracts/User/RegisterUserRequest.cs renamed to src/CodeBeam.UltimateAuth.Users/Contracts/RegisterUserRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace CodeBeam.UltimateAuth.Core.Contracts
1+
namespace CodeBeam.UltimateAuth.Server.Users.Contracts
22
{
33
/// <summary>
44
/// Request to register a new user with credentials.

0 commit comments

Comments
 (0)