Interface IAuthService
- Namespace
- Builvero.Application.Services
- Assembly
- Builvero.Application.dll
Defines the contract for user authentication operations including signup, login, OAuth, and JWT token generation.
public interface IAuthService
Remarks
This interface provides methods for:
- User registration with invitation code validation
- Email/password authentication
- OAuth authentication (Google, LinkedIn) with account linking
- JWT token generation for authenticated sessions
Methods
GenerateJwtTokenAsync(Guid, string, string, string, CancellationToken)
Generates a JWT (JSON Web Token) for user authentication.
Task<string> GenerateJwtTokenAsync(Guid userId, string email, string role, string status, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user.
emailstringThe email address of the user.
rolestringThe role of the user (e.g., "User", "Admin", "Moderator").
statusstringThe status of the user (e.g., "Active").
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
HandleOAuthCallbackAsync(OAuthProvider, string, string, string?, string?, string?, CancellationToken)
Handles OAuth authentication callback from external providers (Google, LinkedIn, etc.).
Task<AuthResponse> HandleOAuthCallbackAsync(OAuthProvider provider, string providerUserId, string email, string? name, string? photoUrl, string? invitationCode, CancellationToken cancellationToken = default)
Parameters
providerOAuthProviderThe OAuth provider (e.g., Google, LinkedIn).
providerUserIdstringThe unique user identifier from the OAuth provider.
emailstringThe email address from the OAuth provider.
namestringThe user's full name from the OAuth provider, if available.
photoUrlstringThe user's profile photo URL from the OAuth provider, if available.
invitationCodestringOptional invitation code for new user registration.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<AuthResponse>
An AuthResponse containing the JWT token and user information.
Exceptions
- Exception
Thrown when account is disabled, invitation code is required but missing/invalid, or email is already registered with a different auth method.
LoginAsync(LoginRequest, CancellationToken)
Authenticates a user with email and password credentials.
Task<AuthResponse> LoginAsync(LoginRequest request, CancellationToken cancellationToken = default)
Parameters
requestLoginRequestThe login request containing email and password.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<AuthResponse>
An AuthResponse containing the JWT token and user information.
Exceptions
- Exception
Thrown when credentials are invalid or account is disabled.
SignupAsync(SignupRequest, CancellationToken)
Registers a new user account with email and password.
Task<AuthResponse> SignupAsync(SignupRequest request, CancellationToken cancellationToken = default)
Parameters
requestSignupRequestThe signup request containing email, password, password confirmation, and invitation code.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<AuthResponse>
An AuthResponse containing the JWT token and user information.
Exceptions
- Exception
Thrown when invitation code is invalid, email is already registered, or password validation fails.
VerifyEmailAsync(VerifyEmailRequest, CancellationToken)
Verifies a user's email using a verification code and activates the account.
Task<AuthResponse> VerifyEmailAsync(VerifyEmailRequest request, CancellationToken cancellationToken = default)
Parameters
requestVerifyEmailRequestThe verification request containing email and code.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<AuthResponse>
An AuthResponse containing a JWT token and user info once verified.