Interface IAuthService
Interface for authentication services including user registration, login, token management, and password handling.
Namespace: OEMS.Core.Application.ApplicationServiceInterfaces
Assembly: OEMS.Core.dll
Syntax
public interface IAuthService
Methods
ConfirmPasswordResetAsync(string, string)
Confirms a password reset and sets a new password
Declaration
Task<AuthResultDto> ConfirmPasswordResetAsync(string token, string newPassword)
Parameters
Type | Name | Description |
---|---|---|
string | token | Password reset token |
string | newPassword | New password to set |
Returns
Type | Description |
---|---|
Task<AuthResultDto> | Authentication result indicating success or failure |
GenerateJwtToken(User, bool)
Generates a new JWT token for a user.
Declaration
Task<string> GenerateJwtToken(User user, bool rememberMe = false)
Parameters
Type | Name | Description |
---|---|---|
User | user | User for whom to generate the token |
bool | rememberMe | Whether to extend the token's expiration time |
Returns
Type | Description |
---|---|
Task<string> | JWT token string |
GenerateTokenForOrganizationAsync(Guid, Guid)
Declaration
Task<AuthResultDto> GenerateTokenForOrganizationAsync(Guid userId, Guid organizationId)
Parameters
Type | Name | Description |
---|---|---|
Guid | userId | |
Guid | organizationId |
Returns
Type | Description |
---|---|
Task<AuthResultDto> |
HasAllowedDomain(string, List<string>)
Checks if an email address has one of the allowed domains.
Declaration
bool HasAllowedDomain(string email, List<string> allowedDomains)
Parameters
Type | Name | Description |
---|---|---|
string | Email address to check |
|
List<string> | allowedDomains | List of allowed domain names |
Returns
Type | Description |
---|---|
bool | True if the email domain is allowed, otherwise false |
HashPassword(string)
Hashes a password using a secure cryptographic algorithm.
Declaration
(string passwordHash, string salt) HashPassword(string password)
Parameters
Type | Name | Description |
---|---|---|
string | password | Plain text password to hash |
Returns
Type | Description |
---|---|
(string passwordHash, string salt) | Tuple containing the password hash and salt |
InitiatePasswordResetAsync(string, string?)
Initiates a password reset process by creating a token and sending an email
Declaration
Task<bool> InitiatePasswordResetAsync(string email, string? requestIp = null)
Parameters
Type | Name | Description |
---|---|---|
string | Email address of the user requesting password reset |
|
string | requestIp | IP address from which the request was made |
Returns
Type | Description |
---|---|
Task<bool> | True if the reset email was sent, false otherwise |
IsValidPassword(string)
Validates whether a password meets the system's security requirements.
Declaration
bool IsValidPassword(string password)
Parameters
Type | Name | Description |
---|---|---|
string | password | Password to validate |
Returns
Type | Description |
---|---|
bool | True if the password is valid, otherwise false |
LoginAsync(LoginRequestDto)
Authenticates a user based on login credentials.
Declaration
Task<AuthResultDto> LoginAsync(LoginRequestDto model)
Parameters
Type | Name | Description |
---|---|---|
LoginRequestDto | model | Login credentials including email and password |
Returns
Type | Description |
---|---|
Task<AuthResultDto> | Authentication result with JWT token and refresh token if successful |
LogoutAsync(HttpContext)
Logs out a user by invalidating their tokens.
Declaration
Task LogoutAsync(HttpContext httpContext)
Parameters
Type | Name | Description |
---|---|---|
HttpContext | httpContext | HTTP context for the current request |
Returns
Type | Description |
---|---|
Task | Async task representing the logout operation |
RefreshTokenAsync(User, string)
Refreshes an expired JWT token using a valid refresh token.
Declaration
Task<AuthResultDto> RefreshTokenAsync(User user, string refreshToken)
Parameters
Type | Name | Description |
---|---|---|
User | user | The user requesting a token refresh |
string | refreshToken | The refresh token to validate |
Returns
Type | Description |
---|---|
Task<AuthResultDto> | New authentication result with updated JWT token and refresh token |
RegisterUserAsync(RegisterRequestDto)
Registers a new user in the system or completes registration for a placeholder user.
Declaration
Task<AuthResultDto> RegisterUserAsync(RegisterRequestDto model)
Parameters
Type | Name | Description |
---|---|---|
RegisterRequestDto | model | Registration details including username, email, and password |
Returns
Type | Description |
---|---|
Task<AuthResultDto> | Authentication result with JWT token and refresh token if successful |
Remarks
When registering with a token (model.OrganisationId is not empty), this method will:
- Check if a matching inactive user exists with the same email
- If found, update that user with the provided information instead of creating a new one
- Check if an organization user relationship already exists and update it if needed
This special case is designed for organization admin registration where a placeholder user is created during organization creation, and the admin later completes their registration using a token.
ValidatePasswordResetTokenAsync(string)
Validates a password reset token
Declaration
Task<bool> ValidatePasswordResetTokenAsync(string token)
Parameters
Type | Name | Description |
---|---|---|
string | token | Token to validate |
Returns
Type | Description |
---|---|
Task<bool> | True if token is valid and not expired, false otherwise |
ValidatePasswordResetTokenWithBrandingAsync(string)
Validates a password reset token and returns organization branding information
Declaration
Task<PasswordResetValidationResult> ValidatePasswordResetTokenWithBrandingAsync(string token)
Parameters
Type | Name | Description |
---|---|---|
string | token | Token to validate |
Returns
Type | Description |
---|---|
Task<PasswordResetValidationResult> | Validation result with organization branding data |
ValidateTokenAsync(string)
Validates whether a JWT token is valid and not expired.
Declaration
Task<bool> ValidateTokenAsync(string token)
Parameters
Type | Name | Description |
---|---|---|
string | token | JWT token to validate |
Returns
Type | Description |
---|---|
Task<bool> | True if the token is valid, otherwise false |
VerifyPassword(string, string, string)
Verifies a password against a stored hash and salt.
Declaration
bool VerifyPassword(string password, string storedHash, string storedSalt)
Parameters
Type | Name | Description |
---|---|---|
string | password | Plain text password to verify |
string | storedHash | Previously stored password hash |
string | storedSalt | Previously stored salt used for hashing |
Returns
Type | Description |
---|---|
bool | True if password matches, otherwise false |