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 ¶
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 ¶
Authenticate implements auth.Authenticator.