Services

Interfaces et implementations des services metier de Place API

Services

Module Identity

IAuthTokenResponseBuilder

Construit la reponse d'authentification complete incluant les tokens et les informations utilisateur.

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.AuthTokenResponseBuilderVisibilite : internal

internal interface IAuthTokenResponseBuilder
{
    Task<AuthTokensResponse> BuildAsync(
        User user,
        DeviceInfo device,
        CancellationToken cancellationToken);
}

Responsabilites :

  • Recuperer les roles de l'utilisateur (directs et via groupes)
  • Construire les claims JWT
  • Generer l'access token et le refresh token
  • Creer une session en base
  • Assembler la reponse AuthTokensResponse

ITokenService

Generation des tokens JWT et refresh tokens.

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.TokenServiceVisibilite : internal

internal interface ITokenService
{
    string GenerateAccessToken(IEnumerable<Claim> claims);
    string GenerateRefreshToken();
}
  • GenerateAccessToken : cree un JWT signe avec RSA, contenant les claims utilisateur
  • GenerateRefreshToken : genere une chaine aleatoire cryptographiquement sure

ISessionReader / ISessionWriter / ISessionCleanup

Gestion complete du cycle de vie des sessions.

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.SessionServiceVisibilite : internal

internal interface ISessionReader
{
    Task<UserSession?> FindBySessionIdAsync(SessionId sessionId, CancellationToken ct);
    Task<UserSession?> FindByRefreshTokenHashAsync(HashedToken tokenHash, CancellationToken ct);
    Task<UserSession?> FindByPreviousTokenHashAsync(HashedToken tokenHash, CancellationToken ct);
    Task<IReadOnlyList<UserSession>> GetActiveSessionsByUserIdAsync(UserId userId, CancellationToken ct);
}

internal interface ISessionWriter
{
    Task<UserSession> CreateSessionAsync(NewSessionData data, CancellationToken ct);
    Task<bool> RotateTokenAsync(UserSession session, HashedToken newHash, CancellationToken ct);
    Task<bool> RevokeSessionAsync(SessionId sessionId, RevocationReason? reason, CancellationToken ct);
    Task<int> RevokeAllUserSessionsAsync(UserId userId, SessionId? exclude, RevocationReason reason, CancellationToken ct);
    Task RevokeFamilyAsync(TokenFamilyId familyId, RevocationReason reason, CancellationToken ct);
}

internal interface ISessionCleanup
{
    Task<int> CleanupExpiredSessionsAsync(CancellationToken ct);
    Task<int> RevokeSessionsWithoutDeviceIdAsync(RevocationReason reason, CancellationToken ct);
}

IUserRegistrationService

Creation de comptes utilisateur avec validation.

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.UserRegistrationServiceVisibilite : internal

internal interface IUserRegistrationService
{
    Task<UserCreationResult> CreateUserWithPasswordAsync(
        UserProfileData profile, string password, CancellationToken ct);

    Task<UserCreationResult> CreateUserWithExternalProviderAsync(
        UserProfileData profile, CancellationToken ct);
}

UserCreationResult (union discriminee) :

VarianteDescription
Success(User, IReadOnlyList<string> Roles)Creation reussie
DuplicateEmailEmail deja utilise
WeakPassword(IReadOnlyList<string> Errors)Mot de passe trop faible
CreationFailed(IReadOnlyList<string> Errors)Autre erreur de creation

IOtpService

Generation et validation de codes OTP.

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.OtpServiceVisibilite : public (interface), internal (implementation)

public interface IOtpService
{
    Task<string> GenerateOtpAsync(Guid userId, string purpose, CancellationToken ct);
    Task<bool> ValidateOtpAsync(Guid userId, string code, string purpose, CancellationToken ct);
}

En mode developpement, un OtpServiceStub retourne toujours "000000".

ITwoFactorService

Gestion de l'authentification a deux facteurs (TOTP).

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.TwoFactorService

public interface ITwoFactorService
{
    Task<bool> IsTwoFactorEnabledAsync(Guid userId, CancellationToken ct);
    Task<bool> ValidateTwoFactorAsync(Guid userId, string code, CancellationToken ct);
}

ITwoFactorChallengeService

Gestion des challenges temporaires pour le flux 2FA.

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.TwoFactorChallengeService

public interface ITwoFactorChallengeService
{
    Task<string> CreateChallengeAsync(Guid userId, CancellationToken ct);
    Task<Guid?> ValidateAndConsumeAsync(string challengeToken, CancellationToken ct);
}

IPasswordPolicyService

Politique de mot de passe avec historique.

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.PasswordPolicyService

public interface IPasswordPolicyService
{
    Task<bool> IsPasswordInHistoryAsync(Guid userId, string passwordHash, CancellationToken ct);
    Task RecordPasswordChangeAsync(Guid userId, string passwordHash, CancellationToken ct);
}

IPasswordExpiryService

Verification de l'expiration du mot de passe.

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.PasswordExpiryServiceVisibilite : internal

internal interface IPasswordExpiryService
{
    bool IsPasswordExpired(User user);
    bool IsInWarningPeriod(User user);
    int DaysUntilExpiry(User user);
}

ISecurityAudit

Journalisation structuree de tous les evenements de securite.

Namespace : Identity.ServicesImplementation : Identity.Services.SecurityAuditVisibilite : public (interface), internal (implementation)

Methodes principales :

void LogRegistrationSuccess(Guid userId, string? ipAddress);
void LogLoginSuccess(Guid userId, LoginAuditContext context);
void LogLoginFailure(string email, LoginAuditContext context, string reason);
void LogTokenRefresh(Guid userId, string? ipAddress);
void LogReplayDetected(Guid userId, Guid tokenFamilyId, string? ipAddress);
void LogAllSessionsRevoked(Guid userId, string reason, int revokedCount, Guid? excludedSessionId);
void LogLogout(Guid userId, string? ipAddress);
void LogSocialLoginSuccess(Guid userId, string provider, LoginAuditContext context);
void LogSocialRegistrationSuccess(Guid userId, string provider, string? ipAddress);
void LogSocialLoginFailure(string provider, string reason, LoginAuditContext context);
void LogAccountLinked(Guid userId, string provider, string? ipAddress);
void LogAccountUnlinked(Guid userId, string provider, string? ipAddress);
void LogAdminSessionRevocation(Guid adminId, Guid targetUserId, string? ipAddress);
void LogSessionBindingMismatch(Guid userId, string? expectedIp, string? actualIp);
void LogTwoFactorEnabled(Guid userId, string? ipAddress);
void LogTwoFactorDisabled(Guid userId, string? ipAddress);
void LogTwoFactorLoginSuccess(Guid userId, LoginAuditContext context);
void LogTwoFactorLoginFailure(Guid userId, LoginAuditContext context, string reason);
void LogRecoveryCodesRegenerated(Guid userId, string? ipAddress);
void LogRecoveryCodeUsed(Guid userId, string? ipAddress);

IDeviceInfoProvider

Extraction des informations de l'appareil depuis le contexte HTTP.

Namespace : Identity.ServicesImplementation : Identity.Services.DeviceInfoProviderVisibilite : internal

internal interface IDeviceInfoProvider
{
    DeviceInfo GetDeviceInfo();
}

Utilise UAParser pour parser le User-Agent et classifier l'appareil (Mobile, Desktop, Tablet, Bot).

IGroupRoleService

Gestion des roles via les groupes.

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.GroupRoleService

IPermissionService

Gestion des permissions basees sur les roles.

Namespace : Identity.ServicesImplementation : Identity.Infrastructure.Services.PermissionService

IProviderLinkingService / ISocialAuthProvider / ISocialTokenValidator

Services d'authentification sociale :

  • IProviderLinkingService : liaison/deliaison de comptes sociaux
  • ISocialAuthProvider : resolution du provider social
  • ISocialTokenValidator : validation des tokens sociaux (Google, Facebook, Apple)

Module Audit

IAuditLogWriter

Persistance des evenements d'audit avec diffusion SignalR.

Namespace : Audit.ServicesImplementation : Audit.Services.AuditLogWriter

public interface IAuditLogWriter
{
    Task WriteAsync(AuditEventV1 auditEvent, CancellationToken cancellationToken);
}

Module Messaging

IEmailSender

Envoi d'emails via SMTP.

Namespace : Messaging.ServicesImplementation : Messaging.Infrastructure.Email.SmtpEmailSender

internal interface IEmailSender
{
    Task SendAsync(string to, string subject, string htmlBody, string? replyTo, CancellationToken ct);
}

ISmsSender

Envoi de SMS via AWS SNS.

Namespace : Messaging.ServicesImplementation : Messaging.Infrastructure.Sms.SnsSmsSender (ou SmsServiceStub)

internal interface ISmsSender
{
    Task SendAsync(string phoneNumber, string body, CancellationToken ct);
}

IPushSender

Envoi de notifications push.

Namespace : Messaging.ServicesImplementation : Messaging.Infrastructure.Push.PushServiceStub

internal interface IPushSender
{
    Task SendAsync(Guid userId, string title, string body, IReadOnlyDictionary<string, string>? data, CancellationToken ct);
}

ITemplateRenderer

Rendu de templates (MJML pour les emails).

Namespace : Messaging.ServicesImplementation : Messaging.Infrastructure.Templates.MjmlTemplateRenderer

internal interface ITemplateRenderer
{
    string Render(string templateName, IReadOnlyDictionary<string, string> variables);
}