auth

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyIDFromContext

func KeyIDFromContext(ctx context.Context) string

KeyIDFromContext returns the authenticated key id, or "" if unauthenticated.

func New

func New(store *KeyStore, requiredScope string) func(http.Handler) http.Handler

New returns middleware that requires a Bearer token matching one of the keys currently held by store, AND that the matching key has the requiredScope. The store snapshot is read per request, so a SIGHUP-triggered reload takes effect on the next inbound request.

On failure: 401 (no/invalid token) or 403 (missing scope), with a JSON body.

Types

type KeyStore

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

KeyStore is an atomically-swappable snapshot of the bearer-key list. It is safe for concurrent Load() and Store() — readers see either the previous snapshot or the new one, never a partial mix.

The middleware reads the snapshot per-request, so a SIGHUP reload in main is reflected on the next inbound request without restarting the process or interrupting any in-flight stream.

func NewKeyStore

func NewKeyStore(initial []config.APIKey) *KeyStore

NewKeyStore returns a store seeded with the initial key list.

func (*KeyStore) Load

func (s *KeyStore) Load() []config.APIKey

Load returns the current snapshot. The returned slice must not be mutated.

func (*KeyStore) Store

func (s *KeyStore) Store(keys []config.APIKey)

Store atomically replaces the live key list. A nil or empty slice is allowed but means every subsequent request will fail authentication.

Jump to

Keyboard shortcuts

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