web

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHashPassword        = errors.New("password hashing failed")
	ErrDbInsertUser        = errors.New("failed to insert user")
	ErrParsingJwt          = errors.New("failed to parse JWT")
	ErrJwtMethodBad        = errors.New("invalid JWT signing method")
	ErrJwtInvalid          = errors.New("JWT not found in database")
	ErrJwtInvalidInDb      = errors.New("JWT marked as invalid in database")
	ErrDbInsertToken       = errors.New("failed to insert token")
	ErrJwtGoodAccBadRef    = errors.New("access token was good but refresh was bad")
	ErrDbSelectUserSubject = errors.New("failed to select user subject")
	ErrUuidFailed          = errors.New("failed to generate UUID")
	ErrImpossible          = errors.New("this should be an impossible state")
)

System errors

Functions

func CookieDecryptJwt

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

func CookieDelete

func CookieDelete(w http.ResponseWriter, name string)

func CookieRefreshOrDelete

func CookieRefreshOrDelete(w http.ResponseWriter, r *http.Request) (string, string, bool)

func CookieSetTokens

func CookieSetTokens(w http.ResponseWriter, a string, r string)

func HttpRedirect

func HttpRedirect(w http.ResponseWriter, r *http.Request, redirectFunc func(r *http.Request) string, defaultRoute string) bool

func InitJwt

func InitJwt(params PasswordJwtParams) error

func JwtConfig

func JwtConfig() *configJwt

func MiddlewareAuth

func MiddlewareAuth(next http.Handler) http.Handler

This middleware handles the following cases:

  • If User's access and refresh are both valid, insert AuthContext struct into request context
  • If User's access is invalid and refresh is valid, refresh JWTs
  • If User's access and refresh are both invalid, delete JWTs

func NewTokenPair

func NewTokenPair(j JwtParams) (string, string, string, error)

func ParseOrRefreshToken

func ParseOrRefreshToken(a string, r string) (string, string, error)

func RejectSubroute

func RejectSubroute(path string) alice.Constructor

This returned an alice.Constructor instead of being an alice.Constructor because it requires an argument (path string).

Types

type CustomClaims

type CustomClaims struct {
	jwt.RegisteredClaims
	JwtType  string `json:"jwt_type"`
	Family   string `json:"family"`
	UserName string `json:"user"`
}

func ParseToken

func ParseToken(t string) (CustomClaims, error)

type JwtParams

type JwtParams struct {
	Subject  string `json:"sub"`
	Family   string `json:"family"`
	UserName string `json:"user"`
}

type Locations

type Locations struct {
	SignIn            string
	SignUp            string
	Forgot            string
	Change            string
	Totp              string
	SignOut           string
	SignOutEverywhere string
	Styles            string
}

type PasswordJwtParams

type PasswordJwtParams struct {
	Secret         string
	PublicKeyPath  string
	PrivateKeyPath string
}

Jump to

Keyboard shortcuts

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