route

package
v0.99.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package route provides HTTP route registration and discovery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessTokenIsExpired added in v0.99.0

func AccessTokenIsExpired(p AccessToken) bool

AccessTokenIsExpired reports whether the token expiry is before now. Matches store.ParameterIsExpired semantics (zero time is treated as expired).

func Authorize

func Authorize(handler fiber.Handler) fiber.Handler

Authorize validates the access token and rejects tokens with no scopes.

func CheckAccessToken

func CheckAccessToken(accessToken string) (uid types.Uid, isValid bool)

func DeleteAccessToken added in v0.96.0

func DeleteAccessToken(ctx context.Context, raw string) error

DeleteAccessToken removes both the hashed and legacy plaintext parameter rows for raw.

func ErrorResponse

func ErrorResponse(ctx fiber.Ctx, text string) error

func GetAccessToken

func GetAccessToken(req *http.Request) string

GetAccessToken extracts the API key from Cookie, X-AccessToken, or Authorization Bearer. Query and form parameters are intentionally ignored to avoid token leakage via URLs/logs.

func GetIntParam

func GetIntParam(ctx fiber.Ctx, name string) int64

func GetParam added in v0.92.0

func GetParam(ctx fiber.Ctx) types.KV

func GetScopes added in v0.92.0

func GetScopes(ctx fiber.Ctx) []string

func GetTopic

func GetTopic(ctx fiber.Ctx) string

func GetUid

func GetUid(ctx fiber.Ctx) types.Uid

func RequireScope added in v0.92.0

func RequireScope(scope string, handler fiber.Handler) fiber.Handler

func RequireServiceScope added in v0.96.0

func RequireServiceScope(group, method string, handler fiber.Handler) fiber.Handler

RequireServiceScope enforces the default minimum scope for /service/{group} routes.

func ScopeHandler added in v0.92.0

func ScopeHandler(ctx fiber.Ctx, scope string) bool

func SetAccessTokenStore added in v0.99.0

func SetAccessTokenStore(s AccessTokenStore)

SetAccessTokenStore wires the persistence backend used by token lookup helpers.

func SetAuditor added in v0.92.0

func SetAuditor(a audit.Auditor)

SetAuditor sets the global auditor used for auth event recording.

func WebService

func WebService(app *fiber.App, group string, rs ...*Router)

Types

type AccessToken added in v0.99.0

type AccessToken struct {
	ID        int64
	Flag      string
	Params    map[string]any
	ExpiredAt time.Time
}

AccessToken is the route-layer view of a persisted access-token parameter.

func LookupAccessToken added in v0.96.0

func LookupAccessToken(ctx context.Context, raw string) (AccessToken, error)

LookupAccessToken resolves an access token parameter by SHA-256 hash key. Legacy plaintext rows are migrated to the hash key on first successful lookup.

type AccessTokenStore added in v0.99.0

type AccessTokenStore interface {
	Get(ctx context.Context, flag string) (AccessToken, error)
	Set(ctx context.Context, flag string, params types.KV, expiredAt time.Time) error
	Delete(ctx context.Context, flag string) error
}

AccessTokenStore persists access-token parameters without exposing ORM types.

type AuthLevel added in v0.29.3

type AuthLevel int
const (
	NoAuth AuthLevel = 1
)

type Option

type Option func(r *Router)

func WithNotAuth

func WithNotAuth() Option

WithNotAuth skips token/scope authorization. Use only for intentionally public endpoints (login/setup/CSRF, inbound webhooks). Authenticated UI and APIs must omit this option so Authorize runs by default.

type RequestContext added in v0.92.0

type RequestContext struct {
	UID    types.Uid
	Topic  string
	Param  types.KV
	Scopes []string
}

RequestContext is a typed struct stored in fiber.Locals after authorization. It carries the authenticated user identity, request metadata, and scopes.

func GetRequestContext added in v0.92.0

func GetRequestContext(ctx fiber.Ctx) *RequestContext

GetRequestContext returns the typed RequestContext from fiber.Locals. Returns nil if the request was not authorized.

type Router

type Router struct {
	Method        string
	Path          string
	Function      fiber.Handler
	Documentation string
	AuthLevel     AuthLevel
}

func Route

func Route(method, path string, function fiber.Handler, options ...Option) *Router

Jump to

Keyboard shortcuts

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