Documentation
¶
Overview ¶
Package auth manages API tokens shared by every protocol: REST requests (Authorization: Bearer / X-API-Token / ?token=), and RESP/TCP clients (AUTH <token>).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromRequest ¶
FromRequest extracts a token from an HTTP request: Authorization header ("Bearer x", "Token x" or the bare token), X-API-Token header or the token query parameter (needed for browser WebSockets).
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager stores tokens. It is safe for concurrent use.
func NewManager ¶
NewManager creates a manager. When enabled is false every check succeeds.
func (*Manager) Generate ¶
Generate creates, stores and returns a new random token. Generated tokens live in memory only and disappear on restart.
type TokenInfo ¶
type TokenInfo struct {
ID string `json:"id"` // masked token, safe to display
CreatedAt time.Time `json:"created_at"`
LastUsed time.Time `json:"last_used,omitzero"`
UsageCount int64 `json:"usage_count"`
FromConfig bool `json:"from_config"`
}
TokenInfo describes a token without exposing it.