[FA-55] Finished aside from deactivation/integration events

This commit is contained in:
gamer147
2025-12-29 14:09:41 -05:00
parent c0290cc5af
commit 01d3b94050
19 changed files with 377 additions and 75 deletions

View File

@@ -1,4 +1,6 @@
using System.Net.Http.Json;
using System.Text;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace FictionArchive.Service.UserService.Services.AuthenticationClient.Authentik;
@@ -6,11 +8,16 @@ public class AuthentikClient : IAuthenticationServiceClient
{
private readonly HttpClient _httpClient;
private readonly ILogger<AuthentikClient> _logger;
private readonly AuthentikConfiguration _configuration;
public AuthentikClient(HttpClient httpClient, ILogger<AuthentikClient> logger)
public AuthentikClient(
HttpClient httpClient,
ILogger<AuthentikClient> logger,
IOptions<AuthentikConfiguration> configuration)
{
_httpClient = httpClient;
_logger = logger;
_configuration = configuration.Value;
}
public async Task<AuthentikUserResponse?> CreateUserAsync(string username, string email, string displayName)
@@ -25,7 +32,9 @@ public class AuthentikClient : IAuthenticationServiceClient
try
{
var response = await _httpClient.PostAsJsonAsync("/api/v3/core/users/", request);
var json = JsonConvert.SerializeObject(request);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync("/api/v3/core/users/", content);
if (!response.IsSuccessStatusCode)
{
@@ -36,7 +45,8 @@ public class AuthentikClient : IAuthenticationServiceClient
return null;
}
var userResponse = await response.Content.ReadFromJsonAsync<AuthentikUserResponse>();
var responseJson = await response.Content.ReadAsStringAsync();
var userResponse = JsonConvert.DeserializeObject<AuthentikUserResponse>(responseJson);
_logger.LogInformation("Successfully created user {Username} in Authentik with pk {Pk}",
username, userResponse?.Pk);
@@ -54,7 +64,7 @@ public class AuthentikClient : IAuthenticationServiceClient
try
{
var response = await _httpClient.PostAsync(
$"/api/v3/core/users/{authentikUserId}/recovery_email/",
$"/api/v3/core/users/{authentikUserId}/recovery_email/?email_stage={_configuration.EmailStageId}",
null);
if (!response.IsSuccessStatusCode)