auth

package
v0.0.21 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminOnly

func AdminOnly(next http.Handler) http.Handler

AdminOnly is a middleware that restricts access to admin users only. It checks if the username retrieved by GetRequestUsername is "admin".

func CheckConnectivity added in v0.0.13

func CheckConnectivity(ip string, port int)

CheckConnectivity periodically checks the health endpoint of the server using its public IP and port. It runs in a loop, making requests every minute with jitter. It uses an HTTP client configured to skip TLS verification, suitable for self-signed certificates. Errors during the check are logged.

func GenerateAccessToken

func GenerateAccessToken(hmacSecret []byte, username string, expiration time.Time) (string, error)

GenerateAccessToken creates a new JWT access token signed with the HS256 algorithm. It includes the username as the subject ("sub") claim and sets the expiration time ("exp"). The token is signed using the provided hmacSecret.

func GetRequestUsername

func GetRequestUsername(r *http.Request) string

GetRequestUsername retrieves the username stored in the request context by the Middleware. It returns an empty string if the username is not found.

func ListenAndServeTLS added in v0.0.13

func ListenAndServeTLS(dataDir, certPEM, keyPEM string, publicIP string, listenPort int, handler http.Handler) error

func Middleware

func Middleware(hmacSecret []byte, next http.Handler) http.Handler

Middleware is an HTTP middleware that validates JWT tokens from the Authorization header or "token" query parameter. If the token is valid, it extracts the username (subject claim) and stores it in the request context. If the token is missing or invalid, it returns an Unauthorized error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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