Stable user lockout, role and claim calls

This commit is contained in:
2026-10-10 18:14:31 +02:00
parent d3566c5e43
commit 381d5b7e94
11 changed files with 249 additions and 22 deletions
@@ -49,9 +49,17 @@ public class SkorubaUserService(IHttpClientFactory httpClientFactory) : ISkoruba
if (user is null)
return Result.Fail(NotFoundError.Create($"User {userId} not found."));
var updated = user with
var updated = new UserLockOutRequest
{
UserId = userId.ToString(),
UserName = user.UserName,
Email = user.Email,
EmailConfirmed = user.EmailConfirmed,
PhoneNumber = user.PhoneNumber,
PhoneNumberConfirmed = user.PhoneNumberConfirmed,
LockoutEnabled = true,
TwoFactorEnabled = user.TwoFactorEnabled,
AccessFailedCount = user.AccessFailedCount,
LockoutEnd = disabled ? DateTimeOffset.UtcNow.AddYears(100) : null
};
@@ -97,7 +105,7 @@ public class SkorubaUserService(IHttpClientFactory httpClientFactory) : ISkoruba
var httpClient = httpClientFactory.CreateClient(SkorubaHttpClient);
var payload = new { UserId = userId, RoleId = roleId };
var response = await httpClient.PostAsJsonAsync($"api/users/{userId}/roles", payload, cancellationToken);
var response = await httpClient.PostAsJsonAsync($"api/users/roles", payload, cancellationToken);
return Result.OkIf(response.IsSuccessStatusCode, CreateError.Create("Failed to add user role."));
}));
@@ -106,7 +114,17 @@ public class SkorubaUserService(IHttpClientFactory httpClientFactory) : ISkoruba
await Result.Try((Func<Task<Result>>)(async () =>
{
var httpClient = httpClientFactory.CreateClient(SkorubaHttpClient);
var response = await httpClient.DeleteAsync($"api/users/{userId}/roles/{roleId}", cancellationToken);
var request = new HttpRequestMessage(HttpMethod.Delete, "api/Users/Roles")
{
Content = JsonContent.Create(new
{
userId = userId.ToString(),
roleId = roleId.ToString()
})
};
var response = await httpClient.SendAsync(request, cancellationToken);
return Result.OkIf(response.IsSuccessStatusCode, CreateError.Create("Failed to remove user role."));
}));
@@ -116,17 +134,20 @@ public class SkorubaUserService(IHttpClientFactory httpClientFactory) : ISkoruba
{
var httpClient = httpClientFactory.CreateClient(SkorubaHttpClient);
var result = await httpClient.GetFromJsonAsync<RolesResponse>($"api/users/{userId}/roles?page={page}&pageSize={pageSize}", cancellationToken);
var result = await httpClient.GetFromJsonAsync<RolesResponse>($"api/Users/{userId}/Roles?page={page}&pageSize={pageSize}", cancellationToken);
return Result.FailIf(result is null, NotFoundError.Create($"Roles for user {userId} could not be retrieved."))
.ToResult(result?.Roles?.ToArray() ?? []);
}));
public async Task<Result<Claim[]>> GetRoleClaimsAsync(Guid roleId, int page = 1, int pageSize = 50, CancellationToken cancellationToken = default) =>
public async Task<Result<Claim[]>> GetRoleClaimsAsync(Guid roleId, CancellationToken cancellationToken = default) =>
await Result.Try((Func<Task<Result<Claim[]>>>)(async () =>
{
var httpClient = httpClientFactory.CreateClient(SkorubaHttpClient);
var page = 1;
var pageSize = 100;
var result = await httpClient.GetFromJsonAsync<ClaimsResponse>($"api/roles/{roleId}/claims?page={page}&pageSize={pageSize}", cancellationToken);
return Result.FailIf(result is null, NotFoundError.Create($"Claims for role {roleId} could not be retrieved."))