apikey

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package apikey implements a Bearer-token auth.Authenticator: it reads an Authorization: Bearer <key> header, resolves the key's hash to a live, non-revoked, non-expired api_keys row and its owning user, and returns the corresponding auth.Principal. Issuance/revocation live in the REST handler; this package only reads (plus a throttled last_used_at write).

Index

Constants

This section is empty.

Variables

View Source
var ErrNoCredential = errors.New("apikey: no credential")

ErrNoCredential means the request carried no Bearer Authorization header, so the caller (or a Chain) should fall through to another authenticator.

Functions

This section is empty.

Types

type APIKeySource

type APIKeySource interface {
	GetAPIKeyUserByTokenHash(ctx context.Context, tokenHash string, now time.Time) (store.APIKey, store.User, error)
	TouchAPIKeyLastUsed(ctx context.Context, id string, now time.Time) error
}

APIKeySource is the store surface the authenticator needs.

type Authenticator

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

Authenticator resolves a Bearer API key to a Principal.

func New

func New(src APIKeySource, clock func() time.Time) *Authenticator

New returns an API-key Authenticator. A nil clock defaults to time.Now UTC.

func (*Authenticator) Authenticate

func (a *Authenticator) Authenticate(r *http.Request) (auth.Principal, error)

Authenticate implements auth.Authenticator.

Jump to

Keyboard shortcuts

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