Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewOAuthProviders ¶
NewOAuthProviders initializes and registers the OAuth providers using the Goth library. It accepts a configuration object that contains the necessary credentials and settings for each OAuth provider.
func OAuthCallbackMiddleware ¶
func OAuthCallbackMiddleware(authMiddleware *jwt.GinJWTMiddleware, handleUser func(ctx context.Context, user goth.User) (*dto.OAuthResponseDto, error)) gin.HandlerFunc
OAuthCallbackMiddleware is a Gin middleware function that handles the callback from the OAuth provider. It completes the OAuth authentication, validates the state, and generates a JWT for the authenticated user.
func OAuthMiddleware ¶
func OAuthMiddleware() gin.HandlerFunc
OAuthMiddleware is a Gin middleware function that handles the initial OAuth request. It sets up the necessary state for the OAuth flow, including setting the provider in the context and generating a state cookie to prevent CSRF attacks.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles authentication-related requests
type Service ¶
type Service interface { // RegisterUser handles the process of registering a new user. // It accepts a SignUpRequestDto containing the user's registration details and performs necessary actions such as // validating the input, storing the user's data, and sending a confirmation email. RegisterUser(ctx context.Context, user *dto.SignUpRequestDto) error // LoginUser handles the user login process. // It accepts a SignInRequestDto containing the user's email and password, validates the credentials, // and returns the user's ID if successful. If login fails, it returns an appropriate error. LoginUser(ctx context.Context, request *dto.SignInRequestDto) (string, error) // ResetPassword handles the process of resetting a user's password. // It accepts a PasswordResetRequestDto containing the user's current and new passwords, verifies the current password, // and updates the user's password in the database if validation is successful. ResetPassword(ctx context.Context, request *dto.PasswordResetRequestDto) error // ActivateAccount handles the activation of a user's account. // It accepts a token string, verifies its validity, and activates the account associated with the token. // It returns the user's ID if activation is successful. ActivateAccount(ctx context.Context, token string) (string, error) // GetUserByID retrieves a user's details based on their ID. // It returns a UserResponseDto containing the user's information, or an error if the user is not found. GetUserByID(ctx context.Context, id string) (*userDto.UserResponseDto, error) // SendAccountVerificationEmail sends an account verification email to the user. // It accepts a UserResponseDto containing the user's details, generates a verification token, // and sends the email. Returns an error if the email cannot be sent. SendAccountVerificationEmail(ctx context.Context, requestBody *userDto.UserResponseDto) error // HandleOAuthUser handles the authentication of a user via OAuth. // It accepts a Goth User object containing the OAuth user's details, processes the user (e.g., linking accounts, creating a new user), // and returns an OAuthResponseDto with the necessary information, or an error if the process fails. HandleOAuthUser(ctx context.Context, gothUser goth.User) (*dto.OAuthResponseDto, error) }
Service defines the methods that our authentication service will implement.
func NewAuthService ¶
func NewAuthService(userService user.Service, emailService email.Service, transactionManager postgres.TransactionManager, cfg *config.Config) Service
NewAuthService creates a new instance of authServiceImpl with the provided services and configuration. This function returns an Service interface that uses the authServiceImpl implementation.