authn

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxSessions = 10000

DefaultMaxSessions bounds the session map when no MaxSessions is configured

Variables

This section is empty.

Functions

func GenerateToken

func GenerateToken(role, secret string, expiry ...time.Duration) (string, error)

GenerateToken creates a signed JWT for the given role. If expiry > 0, the token will include exp and iat claims. If expiry == 0, the token has no expiration (for testing or long-lived tokens).

func LimitBody added in v0.8.3

func LimitBody(w http.ResponseWriter, body io.ReadCloser, max int64) io.ReadCloser

LimitBody caps the request body at max bytes. A non-positive max means unlimited, as RequestMaxBytes documents: MaxBytesReader(0) would instead fail on the first byte and block every request with a body.

func Middleware

func Middleware(cfg MiddlewareConfig, forceDBE bool, getDBName GetDatabaseNameFn) heligo.Middleware

Types

type Claims

type Claims struct {
	Role string `json:"role"`
	Id   string `json:"id"`
	jwt.RegisteredClaims
	RawClaims string `json:"-"`
}

func (*Claims) UnmarshalJSON added in v0.2.11

func (c *Claims) UnmarshalJSON(data []byte) error

type GetDatabaseNameFn

type GetDatabaseNameFn func(ctx context.Context, r heligo.Request) string

type MiddlewareConfig

type MiddlewareConfig interface {
	GetDatabase(context.Context, string) (*database.Database, error)
	JWTSecret() string
	AllowAnon() bool
	AnonRole() string
	RequestMaxBytes() int64
	SessionManager() *SessionManager
	GetLogger() *logging.Logger
}

type Session

type Session struct {
	Claims     *Claims
	LastUsedAt time.Time
	Db         *database.Database
	DbConn     *database.DbPoolConn
	// contains filtered or unexported fields
}

A Session for SmoothDB is the way to cache information about a user and his connection to a database

type SessionList

type SessionList struct {
	// contains filtered or unexported fields
}

type SessionManager

type SessionManager struct {
	// contains filtered or unexported fields
}

SessionManager manages user sessions and monitors them efficiently. When disabled, it simply returns Sessions without managing or monitoring.

func NewSessionManager

func NewSessionManager(logger *logging.Logger, enabled bool, shutdown chan struct{}) *SessionManager

func (*SessionManager) SetMaxSessions added in v0.8.3

func (sm *SessionManager) SetMaxSessions(n int)

SetMaxSessions bounds the number of stored sessions (non-positive: default)

func (*SessionManager) SetRetainConnections added in v0.8.3

func (sm *SessionManager) SetRetainConnections(retain bool)

SetRetainConnections selects between "role" mode (true: the prepared connection stays attached to the session between requests) and "claims" mode (false: only the verified claims are cached, the connection goes back to the pool at the end of every request).

func (*SessionManager) Statistics

func (sm *SessionManager) Statistics() SessionStatistics

type SessionStatistics

type SessionStatistics struct {
	Count int
	InUse int
	Users int
}

Jump to

Keyboard shortcuts

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