httpauth

package module
v0.0.0-...-2dc5f29 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

This module provides authentication for the website. It provides convinient and ready to use endpoints for: - login; - logout; - register; - password forgot; - password reset; - tfa; - email change. This module also provides Authentication middleware that checks if user is logged in and sets proper variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(authRequirement AuthRequirement, next http.Handler) http.Handler

Checks if user is logged in and decides based on authRequirement if the user can continue or be redirected.

func AuthTfaTokenExists

func AuthTfaTokenExists(r *http.Request) (*tfaClaims, error)

Returns claims of tfa token and error if the token does not exist or is invalid.

func Config

func Config() error

Reads environment variables and parses HTML and text templates used in this module Additionaly reads ./lang/auth/LangTag.json to load translations.

func GetGrp

func GetGrp(r *http.Request) ([]int, error)

Returns user's group ids from context value or error if it is impossible.

func GetUid

func GetUid(r *http.Request) (int, error)

Returns user id from context value or error if it is impossible.

func GetUname

func GetUname(r *http.Request) (string, error)

Returns user name from context value or error if it is impossible.

func IsLoggedIn

func IsLoggedIn(r *http.Request) bool

Returns true if user is logged in, otherwise false.

func MuxHandle

func MuxHandle(mux *http.ServeMux, standardMiddleware func(AuthRequirement, http.Handler) http.Handler)

Function adds authentication endpoints for http.ServeMux. They all start with "/auth/", so they should not interfere with the rest of application. GET endpoints are: - /auth/refresh - /auth/refresh/logout - /auth/login - /auth/register - /auth/admin - /auth/password_forgot - /auth/tfa - /auth/tfa/password_change - /auth/tfa/email_change

Types

type Alerts

type Alerts struct {
	Http500                 string
	Http400                 string
	UserNotFound            string
	EmailNotFound           string
	PasswordIncorrect       string
	SessionExpired          string
	UnverifiedLoggedOut     string
	InactivityLoggedOut     string
	TokenExpired            string
	UnverifiedToken         string
	TooManyAttemptsNewToken string
	WrongToken              string
	MailResendTooEarly      string
	MailSent                string
	TooLatePasswordChange   string
	TooLateEmailChange      string
	EmailAlreadyExists      string
	LoginAlreadyExists      string
	EmailChanged            string
	PasswordChanged         string
	LoginChanged            string
	TfaEnabled              string
	TfaDisabled             string
	LoginSuccessful         string
	Logout                  string
}

type AuthRequirement

type AuthRequirement int

Enum used for setting auth status for the webpage.

const (
	Allowed AuthRequirement = iota
	Required
	Forbidden
)

type InputNames

type InputNames struct {
	Email          string
	Password       string
	Login          string
	PasswordRepeat string
	Token          string
}

type Texts

type Texts struct {
	Alerts     Alerts
	Validators httpvalidator.ValidatorsLang
	InputNames InputNames
}

Jump to

Keyboard shortcuts

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