auth

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(server *api.Server, logger *zap.SugaredLogger, db *gorm.DB, config *config.Config, metrics *api.PrometheusMetrics)

Types

type AuthHandler

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

func NewAuthHandler

func NewAuthHandler(logger *zap.SugaredLogger, db *gorm.DB, config *config.Config, metrics *api.PrometheusMetrics) *AuthHandler

func (*AuthHandler) CheckUser

func (h *AuthHandler) CheckUser(username, password string) (*relational.User, bool, error)

CheckUser verifies a user's credentials.

It looks up the user by email (username) in the database. If the user is not found, it returns (nil, true, error) where the error is a generic invalid credentials error and the boolean indicates unauthorized access. If a database error occurs, it returns (nil, false, error). If the user is found but the password does not match, it returns (nil, true, error) with the same invalid credentials error. If the credentials are valid, it returns the user, false, and nil error.

Parameters:

  • username: the user's email address
  • password: the user's password

Returns:

  • *relational.User: the user object if credentials are valid, otherwise nil
  • bool: true if unauthorized (invalid credentials), false otherwise
  • error: error if any occurred, or nil

func (*AuthHandler) GetJWK

func (h *AuthHandler) GetJWK(ctx echo.Context) error

GetJWK godoc

@Summary		Get JWK
@Description	Get JSON Web Key (JWK) representation of the JWT public key
@Tags			Auth
@Accept			json
@Produce		json
@Success		200	{object}	authn.JWK
@Failure		500	{object}	api.Error
@Router			/auth/publickey [get]

func (*AuthHandler) GetOAuth2Token

func (h *AuthHandler) GetOAuth2Token(ctx echo.Context) error

GetOAuth2Token godoc

@Summary		Get OAuth2 token
@Description	Get OAuth2 token using username and password
@Tags			Auth
@Accept			x-www-form-urlencoded
@Produce		json
@Param			username	formData	string	true	"Username (email)"
@Param			password	formData	string	true	"Password"
@Success		200			{object}	auth.AuthHandler.GetOAuth2Token.response
@Failure		400			{object}	api.Error
@Failure		401			{object}	api.Error
@Failure		500			{object}	api.Error
@Router			/auth/token [post]

func (*AuthHandler) GetPublicKeyPEM

func (h *AuthHandler) GetPublicKeyPEM(ctx echo.Context) error

GetPublicKeyPEM returns a plaintext representation of the JWT public key in PEM format.

func (*AuthHandler) LoginUser

func (h *AuthHandler) LoginUser(ctx echo.Context) error

LoginUser godoc

@Summary		Login user
@Description	Login user and returns a JWT token and sets a cookie with the token
@Tags			Auth
@Accept			json
@Produce		json
@Param			loginRequest	body		auth.AuthHandler.LoginUser.loginRequest	true	"Login Data"
@Success		200				{object}	handler.GenericDataResponse[auth.AuthHandler.LoginUser.response]
@Failure		400				{object}	api.Error
@Failure		401				{object}	handler.GenericDataResponse[auth.AuthHandler.LoginUser.errorResponse]
@Failure		500				{object}	api.Error
@Router			/auth/login [post]

func (*AuthHandler) Register

func (h *AuthHandler) Register(api *echo.Group)

Jump to

Keyboard shortcuts

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