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 ¶
- func AuthMiddleware(authRequirement AuthRequirement, next http.Handler) http.Handler
- func AuthTfaTokenExists(r *http.Request) (*tfaClaims, error)
- func Config() error
- func GetGrp(r *http.Request) ([]int, error)
- func GetUid(r *http.Request) (int, error)
- func GetUname(r *http.Request) (string, error)
- func IsLoggedIn(r *http.Request) bool
- func MuxHandle(mux *http.ServeMux, ...)
- type Alerts
- type AuthRequirement
- type InputNames
- type Texts
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 ¶
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 IsLoggedIn ¶
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 Texts ¶
type Texts struct {
Alerts Alerts
Validators httpvalidator.ValidatorsLang
InputNames InputNames
}