Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UltimateAuth.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<File Path="Roadmap.md" />
</Folder>
<Folder Name="/Tests/">
<Project Path="tests/CodeBeam.UltimateAuth.Tests.Integration.EfCore/CodeBeam.UltimateAuth.Tests.Integration.EfCore.csproj" Id="51652abe-8f77-4150-94ea-976ca41c8b91" />
<Project Path="tests/CodeBeam.UltimateAuth.Tests.Integration/CodeBeam.UltimateAuth.Tests.Integration.csproj" Id="fe34a0b1-8038-400d-b8ab-02dad7051f2d" />
<Project Path="tests/CodeBeam.UltimateAuth.Tests.Unit/CodeBeam.UltimateAuth.Tests.Unit.csproj" Id="6f4b22da-849a-4a79-b5c5-aee7cb1429a6" />
</Folder>
Expand Down
1 change: 1 addition & 0 deletions src/CodeBeam.UltimateAuth.Core/AssemblyVisibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore")]
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Tests.Unit")]
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Tests.Integration")]
[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Tests.Integration.EfCore")]
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
public enum RefreshTokenPersistence
{
/// <summary>
/// Refresh token store'a yazΔ±lΔ±r.
/// Login, first-issue gibi normal akışlar için.
/// Refresh token persists to the store.
/// </summary>
Persist = 0,

/// <summary>
/// Refresh token store'a yazΔ±lmaz.
/// Rotation gibi âzel akışlarda,
/// caller tarafΔ±ndan kontrol edilir.
/// Refresh token does not persist to the store.
/// </summary>
DoNotPersist = 10
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ο»Ώusing CodeBeam.UltimateAuth.Core.Contracts;
using CodeBeam.UltimateAuth.Server.Options;
using CodeBeam.UltimateAuth.Users.Contracts;

namespace CodeBeam.UltimateAuth.Server.Infrastructure;

// TODO(policy): Move identifier uniqueness decision/enforcement to the Policy layer.
public static class IdentifierUniquenessResolver
{
public static UniquenessScope GetScope(UAuthServerOptions options, UserIdentifierType type)
{
ArgumentNullException.ThrowIfNull(options);

var uniqueness = options.Identifiers.Uniqueness;

return type switch
{
UserIdentifierType.Username => uniqueness.Username,
UserIdentifierType.Email => uniqueness.Email,
UserIdentifierType.Phone => uniqueness.Phone,
_ => uniqueness.Custom
};
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
ο»Ώusing CodeBeam.UltimateAuth.Core.Contracts;
using CodeBeam.UltimateAuth.Users.Contracts;
using CodeBeam.UltimateAuth.Server.Services;
using CodeBeam.UltimateAuth.Users;
using CodeBeam.UltimateAuth.Users.Contracts;

namespace CodeBeam.UltimateAuth.Server.Infrastructure;

public sealed class UserCreateValidator : IUserCreateValidator
{
private readonly IUserIdentifierValidator _identifierValidator;
private readonly IUserIdentifierAvailabilityService _identifierAvailability;
private readonly IUserProfileValidator _profileValidator;

public UserCreateValidator(IUserIdentifierValidator identifierValidator, IUserProfileValidator profileValidator)
public UserCreateValidator(IUserIdentifierValidator identifierValidator, IUserIdentifierAvailabilityService identifierAvailability, IUserProfileValidator profileValidator)
{
_identifierValidator = identifierValidator;
_identifierAvailability = identifierAvailability;
_profileValidator = profileValidator;
}

Expand All @@ -35,6 +38,23 @@ public async Task<UserCreateValidatorResult> ValidateAsync(AccessContext context
}, ct);

errors.AddRange(r.Errors);

if (r.IsValid)
{
var availability = await _identifierAvailability.CheckAsync(
context,
new CheckUserIdentifierAvailabilityRequest
{
Type = UserIdentifierType.Username,
Value = request.UserName
},
ct);

if (!availability.IsAvailable)
{
errors.Add(new UAuthValidationError("username_unavailable", "username"));
}
}
}

if (!string.IsNullOrWhiteSpace(request.Email))
Expand All @@ -46,6 +66,23 @@ public async Task<UserCreateValidatorResult> ValidateAsync(AccessContext context
}, ct);

errors.AddRange(r.Errors);

if (r.IsValid)
{
var availability = await _identifierAvailability.CheckAsync(
context,
new CheckUserIdentifierAvailabilityRequest
{
Type = UserIdentifierType.Email,
Value = request.Email
},
ct);

if (!availability.IsAvailable)
{
errors.Add(new UAuthValidationError("email_unavailable", "email"));
}
}
}

if (!string.IsNullOrWhiteSpace(request.Phone))
Expand All @@ -57,6 +94,25 @@ public async Task<UserCreateValidatorResult> ValidateAsync(AccessContext context
}, ct);

errors.AddRange(r.Errors);

if (r.IsValid)
{
// TODO: CheckAsync also validates identifiers, make them effective.
// TODO: This guard doesn't work with concurrent requests.
var availability = await _identifierAvailability.CheckAsync(context,
new CheckUserIdentifierAvailabilityRequest
{
Type = UserIdentifierType.Phone,
Value = request.Phone
},
ct);

if (!availability.IsAvailable)
{
errors.Add(
new UAuthValidationError("phone_unavailable", "phone"));
}
}
}

var effectiveDisplayName =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ο»Ώusing CodeBeam.UltimateAuth.Core.Contracts;
using CodeBeam.UltimateAuth.Users.Contracts;

namespace CodeBeam.UltimateAuth.Users.Reference;
namespace CodeBeam.UltimateAuth.Server.Services;

public interface IUserIdentifierAvailabilityService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ο»Ώusing System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("CodeBeam.UltimateAuth.Tests.Unit")]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@namespace CodeBeam.UltimateAuth.Client.Blazor
@using CodeBeam.UltimateAuth.Core.Defaults
@using Microsoft.AspNetCore.WebUtilities
@inject IUAuthLoginPageResolver LoginPageResolver
@inject NavigationManager Nav

@code {
Expand All @@ -20,7 +21,7 @@
? value.ToString()
: null;

var loginRoute = UAuthLoginPageDiscovery.Resolve();
var loginRoute = LoginPageResolver.Resolve();

string target;
string? safeReturnUrl = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ private static IServiceCollection AddUltimateAuthClientBlazorInternal(this IServ
services.AddScoped<IReturnUrlProvider, BlazorReturnUrlProvider>();
services.AddScoped<IClientDeviceProvider, ClientDeviceProvider>();

services.TryAddSingleton<IUAuthLoginPageResolver, UAuthLoginPageResolver>();

services.AddAuthorizationCore();

return services;
Expand Down
Loading
Loading