auth

package
v0.44.43 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Authentication logic and JWT operations package.

Index

Constants

View Source
const (
	ACCESS_TOKEN  = "access-token"
	REFRESH_TOKEN = "refresh-token"
)

Variables

View Source
var PathExceptions = []string{
	"/api/v1",
	"/api/v1/auth",
	"/api/v1/auth/logout",
	"/api/v1/dump",
	"/api/v1/live",
	"/api/v1/users/passphrase/request",
	"/api/v1/users/passphrase/reset",
}

These URL paths are to be skipped by the authentication middleware.

Functions

func AuthMiddleware

func AuthMiddleware(next http.Handler) http.Handler

The very authentication middleware entrypoint.

func NewAuthRouter added in v0.44.23

func NewAuthRouter(authController *AuthController) chi.Router

func NewAuthService added in v0.44.23

func NewAuthService(
	tokenRepository models.TokenRepositoryInterface,
	userRepository models.UserRepositoryInterface,
) models.AuthServiceInterface

Types

type AuthController added in v0.44.23

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

func NewAuthController added in v0.44.23

func NewAuthController(authService models.AuthServiceInterface) *AuthController

func (*AuthController) Auth added in v0.44.23

Auth handles the nickname-hashed-passphrase common dual input and tries to authenticate the user.

@Summary Auth an user @Description auth an user @Tags auth @Accept json @Produce json @Param request body auth.AuthUser true "user struct to auth" @Success 200 {object} common.APIResponse{data=auth.Auth.responseData} @Failure 400 {object} common.APIResponse{data=auth.Auth.responseData} @Failure 404 {object} common.APIResponse{data=auth.Auth.responseData} @Failure 500 {object} common.APIResponse{data=auth.Auth.responseData} @Router /auth [post]

func (*AuthController) Logout added in v0.44.23

func (c *AuthController) Logout(w http.ResponseWriter, r *http.Request)

Logout send a client invalidated cookies to cease the session created before.

@Summary Log-out an user @Description log-out an user @Tags auth @Accept json @Produce json @Success 200 {object} common.APIResponse{data=auth.Logout.responseData} @Router /auth/logout [post]

type AuthService added in v0.44.23

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

func (*AuthService) Auth added in v0.44.23

func (s *AuthService) Auth(ctx context.Context, authUserI interface{}) (*models.User, []string, error)

func (*AuthService) Logout added in v0.44.23

func (s *AuthService) Logout(ctx context.Context) error

type AuthUser added in v0.43.7

type AuthUser struct {
	// Nickname is the user's very username.
	Nickname string `json:"nickname"`

	// Passphrase is a legacy format converted to string from a raw byte stream
	// (do not use anymore as this will be removed in future versions).
	Passphrase string `json:"passphrase"`

	// PassphraseHex is a hexadecimal representation of a passphrase (a SHA-512 checksum).
	// Use 'echo $PASS | sha512sum' for example to get the hex format.
	PassphraseHex string `json:"passphrase_hex"`
}

Jump to

Keyboard shortcuts

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