Table of Contents

Class DatabaseUserRepository

Namespace
SEBT.Portal.Infrastructure.Repositories
Assembly
SEBT.Portal.Infrastructure.dll

Database-backed implementation of IUserRepository using Entity Framework Core.

public class DatabaseUserRepository : IUserRepository
Inheritance
object
DatabaseUserRepository
Implements

Constructors

DatabaseUserRepository(PortalDbContext, IIdentifierHasher, IPiiSymmetricEncryption, IEmailLookupHasher)

Database-backed implementation of IUserRepository using Entity Framework Core.

public DatabaseUserRepository(PortalDbContext dbContext, IIdentifierHasher identifierHasher, IPiiSymmetricEncryption piiEncryption, IEmailLookupHasher emailLookupHasher)

Parameters

dbContext PortalDbContext
identifierHasher IIdentifierHasher
piiEncryption IPiiSymmetricEncryption
emailLookupHasher IEmailLookupHasher

Methods

CreateUserAsync(User, CancellationToken)

Creates a new user record.

public Task CreateUserAsync(User user, CancellationToken cancellationToken = default)

Parameters

user User

The user to create.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task

A task representing the asynchronous operation.

GetOrCreateUserAsync(string, CancellationToken)

Gets or creates a user by email. If the user doesn't exist, creates a new one.

public Task<(User user, bool isNewUser)> GetOrCreateUserAsync(string email, CancellationToken cancellationToken = default)

Parameters

email string

The email address of the user.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<(User user, bool isNewUser)>

A tuple containing the existing or newly created user and a boolean indicating if the user was newly created.

GetOrCreateUserByExternalIdAsync(string, string?, CancellationToken)

Gets or creates a user by their external identity provider subject ID. Used for OIDC-authenticated users whose identity is anchored by the IdP's sub claim. Creates a minimal record (no email, no IAL) — those attributes come from IdP claims.

When email is provided and no user exists for the given externalProviderId, falls back to an email-based lookup and adopts that record by setting its ExternalProviderId. This migrates pre-existing email-only user records to the new sub-based identity model. TODO: Remove email fallback migration once all existing users have logged in under the new flow.

public Task<(User user, bool isNewUser)> GetOrCreateUserByExternalIdAsync(string externalProviderId, string? email = null, CancellationToken cancellationToken = default)

Parameters

externalProviderId string
email string
cancellationToken CancellationToken

Returns

Task<(User user, bool isNewUser)>

GetUserByEmailAsync(string, CancellationToken)

Retrieves a user by their email address.

public Task<User?> GetUserByEmailAsync(string email, CancellationToken cancellationToken = default)

Parameters

email string

The email address of the user.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<User>

The user if found; otherwise, null.

GetUserByExternalIdAsync(string, CancellationToken)

Retrieves a user by their external identity provider subject ID.

public Task<User?> GetUserByExternalIdAsync(string externalProviderId, CancellationToken cancellationToken = default)

Parameters

externalProviderId string
cancellationToken CancellationToken

Returns

Task<User>

GetUserByIdAsync(Guid, CancellationToken)

Retrieves a user by their database primary key.

public Task<User?> GetUserByIdAsync(Guid id, CancellationToken cancellationToken = default)

Parameters

id Guid

The user's ID.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<User>

The user if found; otherwise, null.

GetUserBySessionIdAsync(string, CancellationToken)

Retrieves a user by their ID proofing session ID.

public Task<User?> GetUserBySessionIdAsync(string sessionId, CancellationToken cancellationToken = default)

Parameters

sessionId string

The session ID from the proofing provider.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<User>

The user if found; otherwise, null.

UpdateUserAsync(User, CancellationToken)

Updates an existing user record.

public Task UpdateUserAsync(User user, CancellationToken cancellationToken = default)

Parameters

user User

The user to update.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task

A task representing the asynchronous operation.