auth

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package auth provides the compile-time capability token for authenticated requests.

Index

Constants

View Source
const ContextKey = "wbt_authorized"

ContextKey is the Echo context key used to store/retrieve the Authorized token.

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized")

ErrUnauthorized is returned by Authenticate when no valid credential is found.

Functions

This section is empty.

Types

type Authorized

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

Authorized is an opaque capability token proving a request passed auth. The unexported field prevents external construction — only Authenticate() can produce one, so any handler that receives Authorized is guaranteed to have gone through the auth middleware.

Compile-time guarantee: auth.Authorized{} OUTSIDE this package is a compile error because the unnamed field _ is unexported. External callers MUST obtain an Authorized value via Authenticate() or FromContext().

func Authenticate

func Authenticate(apiKey, rawKey, token string) (Authorized, error)

Authenticate validates the provided credentials and returns an Authorized token.

apiKey is the expected API key (configured at startup). rawKey is the value from the X-API-Key header (may be empty). token is the wbt_session cookie value (may be empty).

Returns Authorized{} on success, ErrUnauthorized on failure.

func FromContext

func FromContext(c echo.Context) (Authorized, bool)

FromContext retrieves the Authorized token from an Echo context. Returns (Authorized{}, false) if the context does not carry a valid token — this provides runtime type-safe enforcement: even if a malicious caller stores a non-Authorized value at ContextKey, the type assertion fails safely.

Jump to

Keyboard shortcuts

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