goauth

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized = authError.ErrUnauthorized
	ErrForbidden    = authError.ErrForbidden
	ErrInternal     = authError.ErrInternal
)

Re-export error values

Functions

func Admin

Admin-only routes

func AdminCsrfActive

func AdminCsrfActive(h http.HandlerFunc) http.HandlerFunc

func Auth

Auth attaches authentication context (anonymous allowed)

func Cookies

func Cookies(cfg CookieConfig)

Cookies configures auth cookies (secure, samesite, etc.)

func Errors added in v1.2.0

func Errors(h ErrorHandler)

Errors allows customizing how authentication / authorization errors are presented (JSON, HTML, redirects, etc). Optional — defaults to plain HTTP errors.

func FromContext

func FromContext(ctx context.Context) *tokens.JWTPayload

FromContext returns the JWT payload or nil

func JWTSecret

func JWTSecret(secret []byte)

JWTSecret sets the HMAC secret used to sign JWTs. MUST be called once at startup.

func Login

func Login(w http.ResponseWriter, role string, userID int)

Login issues access + refresh + csrf tokens

func Logout

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

Logout expires cookies and revokes tokens

func Protected

func Protected(h http.HandlerFunc) http.HandlerFunc

Protected = authenticated user (user OR admin)

func ProtectedCsrfActive

func ProtectedCsrfActive(h http.HandlerFunc) http.HandlerFunc

Protected = authenticated browser user (CSRF enforced)

func Require

func Require(roles ...string) func(http.HandlerFunc) http.HandlerFunc

Require enforces one or more roles

func RoleAdmin

func RoleAdmin() string

func RoleAnonymous

func RoleAnonymous() string

func RoleUser

func RoleUser() string

func Roles added in v1.1.0

func Roles(cfg RolesConfig)

Roles configures application role names (optional).

func Tokens added in v1.1.0

func Tokens(cfg TokenConfig)

Tokens configures token lifetimes (optional). Safe defaults are used if not called.

func UseStore

func UseStore(store tokens.TokenStore)

UseStore injects the token persistence backend (sqlite, redis, etc.)

func Verbose added in v1.0.4

func Verbose()

Enables Verbose mode (only for developement)

Types

type CookieConfig added in v1.1.0

type CookieConfig = tokens.CookieConfig

type ErrorHandler added in v1.2.0

type ErrorHandler = authError.ErrorHandler

type RolesConfig added in v1.1.0

type RolesConfig = tokens.Roles

type TokenConfig added in v1.1.0

type TokenConfig = tokens.TokenConfig

Jump to

Keyboard shortcuts

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