authentication

package
v0.0.0-...-8557113 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FacebookAuthURL    = "https://www.facebook.com/v22.0/dialog/oauth"
	FacebookTokenURL   = "https://graph.facebook.com/v22.0/oauth/access_token"
	FacebookProfileURL = "https://graph.facebook.com/v22.0/me"
)
View Source
const (
	RESET_PASSWORD_TOKEN_EXPIRY_DURATION_IN_HOURS = 24
)

Variables

View Source
var FacebookEndpoint = oauth2.Endpoint{
	AuthURL:  FacebookAuthURL,
	TokenURL: FacebookTokenURL,
}

Functions

This section is empty.

Types

type AuthenticationHandler

type AuthenticationHandler struct {
	user.UserService
	AuthenticationService
	message.EmailService
	config.Config
	*validator.Validate
}

func NewAuthenticationHandler

func NewAuthenticationHandler(userService user.UserService, authenticationService AuthenticationService, emailService message.EmailService, config config.Config, validate *validator.Validate) AuthenticationHandler

func (*AuthenticationHandler) Login

func (h *AuthenticationHandler) Login(ctx *gin.Context)

@BasePath /api Login godoc @Summary login @Description login @Tags authentication @Accept json @Produce json @Param LoginRequest body LoginRequest true "Login Request" @Success 200 {object} AuthenticationResponse @Failure 400 {object} exception.ErrorResponse @Failure 401 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/login [post]

func (*AuthenticationHandler) Logout

func (h *AuthenticationHandler) Logout(ctx *gin.Context)

@BasePath /api Logout godoc @Summary logout @Description logout @Tags authentication @Accept json @Produce json @Param Authorization header string true "Bearer token" @Success 200 {object} AuthenticationResponse @Failure 401 {object} exception.ErrorResponse @Failure 404 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/logout [post]

func (*AuthenticationHandler) Oauth2FacebookLogin

func (h *AuthenticationHandler) Oauth2FacebookLogin(ctx *gin.Context)

@BasePath /api Oauth2FacebookLogin godoc @Summary facebook login @Description facebook login @Tags authentication @Success 307 @Failure 400 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/oauth2/facebook [get]

func (*AuthenticationHandler) Oauth2FacebookLoginCallback

func (h *AuthenticationHandler) Oauth2FacebookLoginCallback(ctx *gin.Context)

@BasePath /api Oauth2FacebookLoginCallback godoc @Summary facebook login callback @Description facebook login callback @Tags authentication @Success 200 {object} AuthenticationResponse @Failure 400 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/oauth2/facebook/callback [get]

func (*AuthenticationHandler) Oauth2GoogleLogin

func (h *AuthenticationHandler) Oauth2GoogleLogin(ctx *gin.Context)

@BasePath /api Oauth2GoogleLogin godoc @Summary google login @Description google login @Tags authentication @Accept json @Produce json @Param Oauth2GoogleLoginRequest body Oauth2GoogleLoginRequest true "Oauth2 Google Login Request" @Success 200 {object} AuthenticationResponse @Failure 400 {object} exception.ErrorResponse @Failure 401 {object} exception.ErrorResponse @Failure 404 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/oauth2/google [post]

func (*AuthenticationHandler) RefreshToken

func (h *AuthenticationHandler) RefreshToken(ctx *gin.Context)

@BasePath /api RefreshToken godoc @Summary refresh token @Description refresh token @Tags authentication @Accept json @Produce json @Param Authorization header string true "Bearer token" @Success 200 {object} AuthenticationResponse @Failure 401 {object} exception.ErrorResponse @Failure 404 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/refresh-token [post]

func (*AuthenticationHandler) Register

func (h *AuthenticationHandler) Register(ctx *gin.Context)

@BasePath /api Register godoc @Summary register user @Description register user @Tags authentication @Accept json @Produce json @Param RegisterRequest body RegisterRequest true "Register Request" @Success 200 {object} security.AuthenticatedUser @Failure 400 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/register [post]

type AuthenticationRequest

type AuthenticationRequest struct {
	UserID                int64     `json:"userId"`
	AccessToken           string    `json:"accessToken"`
	RefreshToken          string    `json:"refreshToken"`
	AccessTokenExpiresAt  time.Time `json:"accessTokenExpiresAt"`
	RefreshTokenExpiresAt time.Time `json:"refreshTokenExpiresAt"`
}

type AuthenticationResponse

type AuthenticationResponse struct {
	AccessToken          string    `json:"accessToken"`
	RefreshToken         string    `json:"refreshToken"`
	IdToken              string    `json:"idToken"`
	AccessTokenExpiresAt time.Time `json:"accessTokenExpiresAt"`
}

type AuthenticationService

type AuthenticationService interface {
	CreateAuthentication(ctx context.Context, req AuthenticationRequest) (db.AuthenticationToken, error)
	GetByAccessToken(ctx context.Context, token string) (db.AuthenticationToken, error)
	GetByRefreshToken(ctx context.Context, token string) (db.AuthenticationToken, error)
	DeleteAuthenticationTokenByUserID(ctx context.Context, userID int64) error
}

func NewAuthenticationService

func NewAuthenticationService(datastore db.DataStore, redisClient *goRedis.Client) AuthenticationService

type AuthenticationServiceImpl

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

func (*AuthenticationServiceImpl) CreateAuthentication

func (service *AuthenticationServiceImpl) CreateAuthentication(ctx context.Context, req AuthenticationRequest) (db.AuthenticationToken, error)

func (*AuthenticationServiceImpl) DeleteAuthenticationTokenByUserID

func (service *AuthenticationServiceImpl) DeleteAuthenticationTokenByUserID(ctx context.Context, userID int64) error

func (*AuthenticationServiceImpl) GetByAccessToken

func (service *AuthenticationServiceImpl) GetByAccessToken(ctx context.Context, token string) (db.AuthenticationToken, error)

func (*AuthenticationServiceImpl) GetByRefreshToken

func (service *AuthenticationServiceImpl) GetByRefreshToken(ctx context.Context, token string) (db.AuthenticationToken, error)

type FacebookUserDetails

type FacebookUserDetails struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

type ForgotPasswordRequest

type ForgotPasswordRequest struct {
	Email string `json:"email" validate:"required,email"`
}

type LoginRequest

type LoginRequest struct {
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required"`
}

Uses https://github.com/go-playground/validator for validation

type Oauth2GoogleLoginRequest

type Oauth2GoogleLoginRequest struct {
	Token string `json:"token" validate:"required"`
}

type RegisterRequest

type RegisterRequest struct {
	Name     string `json:"name" validate:"required,min=5,max=100"`
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required"`
}

type ResetPasswordHandler

type ResetPasswordHandler struct {
	ResetPasswordService
	message.EmailService
	config.Config
	*validator.Validate
}

func NewResetPasswordHandler

func NewResetPasswordHandler(service ResetPasswordService, emailService message.EmailService, config config.Config, validate *validator.Validate) ResetPasswordHandler

func (*ResetPasswordHandler) ForgotPassword

func (h *ResetPasswordHandler) ForgotPassword(ctx *gin.Context)

@BasePath /api ForgotPassword godoc @Summary forgot password @Description forgot password @Tags reset password @Accept json @Produce json @Param ForgotPasswordRequest body ForgotPasswordRequest true "Forgot Password Request" @Success 200 {object} common.MessageResponse @Failure 400 {object} exception.ErrorResponse @Failure 404 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/forgot-password [post]

func (*ResetPasswordHandler) GetUserByToken

func (h *ResetPasswordHandler) GetUserByToken(ctx *gin.Context)

@BasePath /api GetUserByToken godoc @Summary get user by token @Description get user by token @Tags reset password @Accept json @Produce json @Param token path string true "token" @Success 200 {object} security.AuthenticatedUser @Failure 400 {object} exception.ErrorResponse @Failure 404 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/token/{token} [get]

func (*ResetPasswordHandler) ResetPassword

func (h *ResetPasswordHandler) ResetPassword(ctx *gin.Context)

@BasePath /api ResetPassword godoc @Summary reset password @Description reset password @Tags reset password @Accept json @Produce json @Param ResetPasswordRequest body ResetPasswordRequest true "Reset Password Request" @Success 200 {object} security.AuthenticatedUser @Failure 400 {object} exception.ErrorResponse @Failure 404 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/new-password [post]

type ResetPasswordRequest

type ResetPasswordRequest struct {
	Password string `json:"password" validate:"required"`
	Token    string `json:"token" validate:"required"`
}

type ResetPasswordService

type ResetPasswordService interface {
	GetUserByEmail(ctx context.Context, email string) (user.UserEntity, error)
	CreateResetPasswordToken(ctx context.Context, userID int64) (db.ResetPasswordToken, error)
	GetUserByResetPasswordToken(ctx context.Context, token string) (user.UserEntity, error)
	UpdatePassword(ctx context.Context, userID int64, password string) error
}

func NewResetPasswordService

func NewResetPasswordService(datastore db.DataStore, userService user.UserService) ResetPasswordService

type ResetPasswordServiceImpl

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

func (*ResetPasswordServiceImpl) CreateResetPasswordToken

func (service *ResetPasswordServiceImpl) CreateResetPasswordToken(ctx context.Context, userID int64) (db.ResetPasswordToken, error)

func (*ResetPasswordServiceImpl) GetUserByEmail

func (service *ResetPasswordServiceImpl) GetUserByEmail(ctx context.Context, email string) (user.UserEntity, error)

func (*ResetPasswordServiceImpl) GetUserByResetPasswordToken

func (service *ResetPasswordServiceImpl) GetUserByResetPasswordToken(ctx context.Context, token string) (user.UserEntity, error)

func (*ResetPasswordServiceImpl) UpdatePassword

func (service *ResetPasswordServiceImpl) UpdatePassword(ctx context.Context, userID int64, password string) error

type VerifyEmailHandler

type VerifyEmailHandler struct {
	VerifyEmailService
	config.Config
	*validator.Validate
}

func NewVerifyEmailHandler

func NewVerifyEmailHandler(service VerifyEmailService, config config.Config, validate *validator.Validate) VerifyEmailHandler

func (*VerifyEmailHandler) VerifyEmail

func (h *VerifyEmailHandler) VerifyEmail(ctx *gin.Context)

@BasePath /api VerifyEmail godoc @Summary verify email @Description verify email @Tags verify email @Accept json @Produce json @Param VerifyEmailRequest body VerifyEmailRequest true "Verify Email Request" @Success 200 {object} security.AuthenticatedUser @Failure 400 {object} exception.ErrorResponse @Failure 404 {object} exception.ErrorResponse @Failure 500 {object} exception.ErrorResponse @Router /v1/verify-email [post]

type VerifyEmailRequest

type VerifyEmailRequest struct {
	Token string `json:"token" validate:"required"`
}

type VerifyEmailService

type VerifyEmailService interface {
	GetUserByVerifyEmailToken(ctx context.Context, token string) (user.UserEntity, error)
	UpdateIsEmailVerified(ctx context.Context, userID int64) error
}

func NewVerifyEmailService

func NewVerifyEmailService(datastore db.DataStore, userService user.UserService) VerifyEmailService

type VerifyEmailServiceImpl

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

func (*VerifyEmailServiceImpl) GetUserByVerifyEmailToken

func (service *VerifyEmailServiceImpl) GetUserByVerifyEmailToken(ctx context.Context, token string) (user.UserEntity, error)

func (*VerifyEmailServiceImpl) UpdateIsEmailVerified

func (service *VerifyEmailServiceImpl) UpdateIsEmailVerified(ctx context.Context, userID int64) error

Jump to

Keyboard shortcuts

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