auth

package
v0.0.0-...-7a2aee4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOAuthProviders

func NewOAuthProviders(cfg *config.Config)

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.

func Router

func Router(router *gin.Engine, handler *Handler, authMiddleware *jwt.GinJWTMiddleware)

Router sets up the routes for authentication-related API endpoints It groups the routes under "api/v1/auth" and assigns handler functions to the routes

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler handles authentication-related requests

func NewAuthHandler

func NewAuthHandler(authService Service, cfg *config.Config) *Handler

NewAuthHandler creates a new instance of Handler with the given Service

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL