Documentation
¶
Index ¶
- func DebugService() *fiber.App
- func Service(log *zap.Logger, db *sqlx.DB, cfg appconf.Cfg) (*fiber.App, error)
- type Auth
- type AuthAPI
- func (a *AuthAPI) DeleteAccountHandler(c *fiber.Ctx) error
- func (a *AuthAPI) GoogleOAuthHandler(c *fiber.Ctx) error
- func (a *AuthAPI) SignInHandler(c *fiber.Ctx) error
- func (a *AuthAPI) SignUpHandler(c *fiber.Ctx) error
- func (a *AuthAPI) UpdateProfileHandler(c *fiber.Ctx) error
- func (a *AuthAPI) VerifyTokenHandler(c *fiber.Ctx) error
- type CheckAPI
- type GoogleOAuthRequest
- type GoogleTokenValidator
- type SignInReq
- type SignUpReq
- type SignUpResp
- type TokenResp
- type UpdateProfileReq
- type UserRepo
- type VerifyTokenReq
- type VerifyTokenResp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Auth ¶
type Auth interface { GenerateToken(claims jwt.Claims) (string, error) ValidateToken(tokenStr string) (auth.Claims, error) CreateClaims(user database.User) jwt.Claims }
Auth provides authentication methods
type AuthAPI ¶
type AuthAPI struct {
// contains filtered or unexported fields
}
AuthAPI describes dependencies for auth endpoints
func NewAuthAPI ¶
func NewAuthAPI(log *zap.Logger, cfg *appconf.Cfg, auth Auth, userRepo UserRepo, googleTokenValidator GoogleTokenValidator) (*AuthAPI, error)
NewAuthAPI return new instance of auth api
func (*AuthAPI) DeleteAccountHandler ¶
DeleteAccountHandler godoc @Summary Delete user account @Description Deletes a user account @Tags auth @Produce json @Param Authorization header string true "Bearer token" @Success 204 "Successfully deleted account" @Failure 401 {object} web.ErrResp "Unauthorized" @Failure 500 {object} web.ErrResp "Internal server error" @Router /account [delete]
func (*AuthAPI) GoogleOAuthHandler ¶
GoogleOAuthHandler godoc @Summary Google OAuth sign in handler @Description Handles Google OAuth 2.0 authentication @Tags auth @Accept json @Produce json @Param token body GoogleOAuthRequest true "Google OAuth token" @Success 200 {object} TokenResp @Failure 400 {object} web.ErrResp @Failure 401 {object} web.ErrResp @Router /oauth/google [post]
func (*AuthAPI) SignInHandler ¶
SignInHandler godoc @Summary Sign in @Description Authenticate a user and return an access token @Tags auth @Accept json @Produce json @Param signin body SignInReq true "User credentials" @Success 200 {object} TokenResp @Failure 400 {object} web.ErrResp @Failure 401 {object} web.ErrResp @Failure 500 {object} web.ErrResp @Router /signin [post]
func (*AuthAPI) SignUpHandler ¶
SignUpHandler godoc @Summary Register a new user @Description Create a new user account with the provided information @Tags auth @Accept json @Produce json @Param signup body SignUpReq true "User signup information" @Success 200 {object} SignUpResp "Successfully registered user" @Failure 400 {object} web.ErrResp "Invalid input data" @Failure 409 {object} web.ErrResp "Username or publisher name already exists" @Failure 500 {object} web.ErrResp "Internal server error" @Router /signup [post]
func (*AuthAPI) UpdateProfileHandler ¶
UpdateProfileHandler godoc @Summary Update user profile @Description Updates the profile information of a user @Tags auth @Accept json @Produce json @Param Authorization header string true "Bearer token" @Param profile body UpdateProfileReq true "Update profile parameters" @Success 200 {object} TokenResp "Returns new access token" @Failure 400 {object} web.ErrResp "Bad request" @Failure 401 {object} web.ErrResp "Invalid password or token" @Failure 404 {object} web.ErrResp "User not found" @Failure 500 {object} web.ErrResp "Internal server error" @Router /account [patch]
func (*AuthAPI) VerifyTokenHandler ¶
VerifyTokenHandler godoc @Summary Verify JWT token @Description Validates a JWT token and returns if it's valid @Tags auth @Accept json @Produce json @Param token body VerifyTokenReq true "Token to verify" @Success 200 {object} VerifyTokenResp @Failure 400 {object} web.ErrResp @Router /token/verify [post]
type CheckAPI ¶
type CheckAPI struct {
// contains filtered or unexported fields
}
CheckAPI has methods for readiness and liveness checking
func NewCheckAPI ¶
NewCheckAPI returns new instance of healthcheck api
type GoogleOAuthRequest ¶
type GoogleOAuthRequest struct {
IDToken string `json:"idToken" validate:"required"`
}
GoogleOAuthRequest represents Google OAuth request
type GoogleTokenValidator ¶
type GoogleTokenValidator interface {
Validate(ctx context.Context, idToken string, audience string) (*idtoken.Payload, error)
}
GoogleTokenValidator provides methods for validating Google ID tokens
type SignInReq ¶
type SignInReq struct { Username string `json:"username" validate:"required"` Password string `json:"password" validate:"required,min=8,max=64"` }
SignInReq represents user sign in request
type SignUpReq ¶
type SignUpReq struct { Username string `json:"username" validate:"required"` DisplayName string `json:"name" validate:"required"` Password string `json:"password" validate:"required,min=8,max=64"` ConfirmPassword string `json:"confirmPassword" validate:"eqfield=Password"` IsPublisher bool `json:"isPublisher"` }
SignUpReq represents user sign up request
type SignUpResp ¶
SignUpResp represents sign up response
type TokenResp ¶
type TokenResp struct {
AccessToken string `json:"accessToken"`
}
TokenResp represents response with JWT
type UpdateProfileReq ¶
type UpdateProfileReq struct { Name *string `json:"name"` Password *string `json:"password" validate:"omitempty,min=8,max=64"` NewPassword *string `json:"newPassword" validate:"omitempty,min=8,max=64"` ConfirmNewPassword *string `json:"confirmNewPassword" validate:"omitempty,min=8,max=64"` }
UpdateProfileReq represents update profile request
type UserRepo ¶
type UserRepo interface { CreateUser(ctx context.Context, user database.User) error UpdateUser(ctx context.Context, user database.User) error DeleteUser(ctx context.Context, userID string) error GetUserByID(ctx context.Context, userID string) (database.User, error) GetUserByUsername(ctx context.Context, username string) (database.User, error) GetUserByOAuth(ctx context.Context, provider string, oauthID string) (database.User, error) CheckUserExists(ctx context.Context, name string, role database.Role) (bool, error) }
UserRepo provides methods for working with user repo
type VerifyTokenReq ¶
type VerifyTokenReq struct {
Token string `json:"token" validate:"jwt"`
}
VerifyTokenReq represents verify JWT request
type VerifyTokenResp ¶
type VerifyTokenResp struct {
Valid bool `json:"valid"`
}
VerifyTokenResp represents verify JWT response