Versions in this module Expand all Collapse all v0 v0.1.1 Nov 12, 2026 Changes in this version type Plugin + func (p *Plugin) GetFor(ctx context.Context, userID, id string) (Key, error) + func (p *Plugin) ListFor(ctx context.Context, userID string, in ListRequest) (ListResult, error) + func (p *Plugin) RevokeFor(ctx context.Context, userID, id string) error + func (p *Plugin) UpdateFor(ctx context.Context, userID string, in UpdateRequest) (Key, error) v0.1.0 Oct 14, 2026 Changes in this version + const ActionCreate + const ActionDelete + const ActionRead + const ActionUpdate + const ColConfigID + const ColCreatedAt + const ColDisabledAt + const ColExpiresAt + const ColHint + const ColID + const ColKeyHash + const ColLastRefillAt + const ColLastUsedAt + const ColMetadata + const ColName + const ColOrganizationID + const ColPermissions + const ColPrefix + const ColRateCount + const ColRateMax + const ColRateWindow + const ColRateWindowStart + const ColRefillAmount + const ColRefillInterval + const ColRemaining + const ColScopes + const ColUpdatedAt + const ColUserID + const DefaultCacheTTL + const DefaultConfig + const DefaultPrefix + const EndpointCreate + const EndpointGet + const EndpointList + const EndpointRevoke + const EndpointUpdate + const MaxCacheTTL + const MaxKeysPerUser + const PluginName + const ResourceAPIKey + const SortAsc + const SortByCreatedAt + const SortByExpiresAt + const SortByLastUsedAt + const SortByName + const SortDesc + const TableAliasKey + const TableNameKey + var ErrBadCacheTTL = errors.New("apikey: the cache TTL is between 0 (the default) and 15 minutes") + var ErrBadConfig = errors.New(...) + var ErrBadKeyPrefix = auth.NewError("apikey.bad_prefix", http.StatusBadRequest, "The key prefix is not allowed.") + var ErrBadLimits = errors.New("apikey: limits are positive and the expiry default lies within its bounds") + var ErrBadLimitsValue = errors.New(...) + var ErrBadList = auth.NewError("apikey.bad_list", http.StatusBadRequest, "The list options are not valid.") + var ErrBadMetadata = auth.NewError("apikey.bad_metadata", http.StatusBadRequest, ...) + var ErrBadName = auth.NewError("apikey.bad_name", http.StatusBadRequest, "The name is too short or too long.") + var ErrBadPermissions = auth.NewError("apikey.bad_permissions", http.StatusBadRequest, ...) + var ErrBadPrefix = errors.New("apikey: a prefix is at least three characters and ends with _") + var ErrBadScope = errors.New("apikey: a scope is non-empty and contains no whitespace") + var ErrExpiryConflict = auth.NewError("apikey.expiry_conflict", http.StatusBadRequest, ...) + var ErrExpiryOutOfRange = auth.NewError("apikey.expiry_out_of_range", http.StatusBadRequest, ...) + var ErrInvalidKey = auth.NewError("apikey.invalid_key", http.StatusUnauthorized, "Invalid API key.") + var ErrKeyDisabled = auth.NewError("apikey.key_disabled", http.StatusUnauthorized, "This API key is disabled.") + var ErrKeyExpired = auth.NewError("apikey.key_expired", http.StatusUnauthorized, "This API key has expired.") + var ErrKeyOwnerGone = auth.NewError("apikey.invalid_owner", http.StatusUnauthorized, ...) + var ErrMetadataDisabled = auth.NewError("apikey.metadata_disabled", http.StatusBadRequest, ...) + var ErrNameRequired = auth.NewError("apikey.name_required", http.StatusBadRequest, "Give the key a name.") + var ErrNoChanges = auth.NewError("apikey.no_changes", http.StatusBadRequest, "Nothing to update.") + var ErrNoScopes = errors.New(...) + var ErrNotFound = auth.NewError("apikey.not_found", http.StatusNotFound, "Not found.") + var ErrNotOrganizationConfig = auth.NewError("apikey.not_organization_config", http.StatusBadRequest, ...) + var ErrNotOrganizationMember = auth.NewError("apikey.not_organization_member", http.StatusForbidden, ...) + var ErrOrganizationIDRequired = auth.NewError("apikey.organization_id_required", http.StatusBadRequest, ...) + var ErrOrganizationKey = auth.NewError("apikey.organization_key", http.StatusUnauthorized, ...) + var ErrOrganizationPermission = auth.NewError("apikey.organization_permission", http.StatusForbidden, ...) + var ErrOrganizationsRequired = errors.New("apikey: an OrganizationOwned configuration needs apikey.WithOrganizations") + var ErrOwnerBlocked = auth.NewError("apikey.owner_blocked", http.StatusUnauthorized, ...) + var ErrPermissionDenied = auth.NewError("apikey.permission_denied", http.StatusForbidden, ...) + var ErrPermissionsOff = auth.NewError("apikey.permissions_off", http.StatusBadRequest, ...) + var ErrPrefixNotDistinct = errors.New(...) + var ErrScopeMissing = auth.NewError("apikey.missing_scope", http.StatusForbidden, "This key does not allow this.") + var ErrShortSecret = errors.New("apikey: Generate returned a secret shorter than 22 characters") + var ErrTooMany = auth.NewError("apikey.too_many", http.StatusConflict, ...) + var ErrUnknownConfig = auth.NewError("apikey.unknown_config", http.StatusBadRequest, ...) + var ErrUnknownScope = auth.NewError("apikey.unknown_scope", http.StatusBadRequest, ...) + var ErrUsageExceeded = auth.NewError("apikey.usage_exceeded", http.StatusTooManyRequests, ...) + var KeyConfig = sqlb.Col[string](TableKey, ColConfigID) + var KeyCreated = sqlb.Col[time.Time](TableKey, ColCreatedAt) + var KeyDisabledAt = sqlb.Col[*time.Time](TableKey, ColDisabledAt) + var KeyExpires = sqlb.Col[*time.Time](TableKey, ColExpiresAt) + var KeyHash = sqlb.Col[[]byte](TableKey, ColKeyHash) + var KeyHint = sqlb.Col[string](TableKey, ColHint) + var KeyID = sqlb.Col[string](TableKey, ColID) + var KeyLastRefillAt = sqlb.Col[*time.Time](TableKey, ColLastRefillAt) + var KeyMetadata = sqlb.Col[*string](TableKey, ColMetadata) + var KeyName = sqlb.Col[string](TableKey, ColName) + var KeyOrganization = sqlb.Col[*string](TableKey, ColOrganizationID) + var KeyPermissions = sqlb.Col[*string](TableKey, ColPermissions) + var KeyPrefix = sqlb.Col[*string](TableKey, ColPrefix) + var KeyRateCount = sqlb.Col[int64](TableKey, ColRateCount) + var KeyRateMax = sqlb.Col[int64](TableKey, ColRateMax) + var KeyRateWindow = sqlb.Col[int64](TableKey, ColRateWindow) + var KeyRateWindowStart = sqlb.Col[*time.Time](TableKey, ColRateWindowStart) + var KeyRefillAmount = sqlb.Col[int64](TableKey, ColRefillAmount) + var KeyRefillInterval = sqlb.Col[int64](TableKey, ColRefillInterval) + var KeyRemaining = sqlb.Col[*int64](TableKey, ColRemaining) + var KeyScopes = sqlb.Col[string](TableKey, ColScopes) + var KeyUpdated = sqlb.Col[*time.Time](TableKey, ColUpdatedAt) + var KeyUsed = sqlb.Col[*time.Time](TableKey, ColLastUsedAt) + var KeyUserID = sqlb.Col[string](TableKey, ColUserID) + var SortByValues = []string + var TableKey = sqlb.Table + type Cache interface + Delete func(ctx context.Context, key string) error + Get func(ctx context.Context, key string) (value []byte, ok bool, err error) + Set func(ctx context.Context, key string, value []byte, ttl time.Duration) error + type CreateRequest struct + Config string + ExpiresIn int64 + ExpiresInDays int + Metadata json.RawMessage + Name string + OrganizationID string + Permissions Permissions + Prefix string + Scopes []string + type CreateResult struct + Key Key + Secret string + type Expiry struct + DefaultDays int + MaxDays int + MinDays int + type GetRequest struct + Config string + ID string + type Key struct + Config string + CreatedAt time.Time + Disabled bool + ExpiresAt *time.Time + Hint string + ID string + LastUsedAt *time.Time + Limits Limits + Metadata json.RawMessage + Name string + OrganizationID string + Permissions Permissions + Prefix string + Scopes []string + UpdatedAt *time.Time + type Limits struct + RateMax int + RateWindow time.Duration + RefillAmount int + RefillInterval time.Duration + Remaining *int + func (l *Limits) UnmarshalJSON(b []byte) error + func (l Limits) MarshalJSON() ([]byte, error) + func (l Limits) None() bool + type ListRequest struct + Config string + Limit string + Offset string + OrganizationID string + Sort string + SortBy string + type ListResult struct + Keys []Key + Limit int + Offset int + Total int + type MemoryCache struct + func NewMemoryCache() *MemoryCache + func NewMemoryCacheAt(now func() time.Time) *MemoryCache + func (m *MemoryCache) Delete(_ context.Context, key string) error + func (m *MemoryCache) Get(_ context.Context, key string) ([]byte, bool, error) + func (m *MemoryCache) Prune() int + func (m *MemoryCache) Set(_ context.Context, key string, value []byte, ttl time.Duration) error + type Option func(*Plugin) + func AllowKeyPrefix(max int) Option + func AllowMetadata() Option + func Configuration(id string, opts ...Option) Option + func DefaultLimits(l Limits) Option + func DefaultPermissions(perms Permissions) Option + func DefaultPermissionsFunc(fn func(ctx context.Context, ownerID string) Permissions) Option + func DefaultScopes(scopes ...string) Option + func DefaultScopesFunc(fn func(ctx context.Context, userID string) []string) Option + func DeferUpdates() Option + func DeleteSpentKeys() Option + func DistinctErrors() Option + func Generate(fn func() string) Option + func HintLength(n int) Option + func MaxKeys(n int) Option + func NameBounds(min, max int) Option + func NameLength(runes int) Option + func OrganizationOwned() Option + func PreCheck(fn func(ctx context.Context, key string) bool) Option + func Prefix(prefix string) Option + func RejectUnknownKeys() Option + func RequireName() Option + func Scopes(scopes ...string) Option + func StampEveryUse() Option + func WithCache(c Cache, ttl time.Duration) Option + func WithExpiry(e Expiry) Option + func WithOrganizations(o Organizations) Option + func WithPermissions(c PermissionChecker) Option + type Organizations interface + APIKeyPermission func(ctx context.Context, orgID, userID, action string) (member, allowed bool, err error) + type OrganizationsFunc func(ctx context.Context, orgID, userID, action string) (member, allowed bool, err error) + func (f OrganizationsFunc) APIKeyPermission(ctx context.Context, orgID, userID, action string) (bool, bool, error) + type PermissionChecker interface + Check func(p Permissions) error + Grants func(held, want Permissions) bool + type Permissions map[string][]string + func (p Permissions) Clone() Permissions + type Plugin struct + func New(opts ...Option) *Plugin + func (p *Plugin) Authorize(ctx context.Context, want Permissions) error + func (p *Plugin) Create(ctx context.Context, in CreateRequest) (CreateResult, error) + func (p *Plugin) CreateFor(ctx context.Context, userID string, in CreateRequest, l Limits) (CreateResult, error) + func (p *Plugin) DeleteOrganizationKeys(ctx context.Context, orgID string) (int64, error) + func (p *Plugin) Get(ctx context.Context, id string) (Key, error) + func (p *Plugin) Init(a *auth.Auth) error + func (p *Plugin) List(ctx context.Context) ([]Key, error) + func (p *Plugin) ListKeys(ctx context.Context, in ListRequest) (ListResult, error) + func (p *Plugin) Name() string + func (p *Plugin) Operations() []auth.Operation + func (p *Plugin) OptionErr() error + func (p *Plugin) OwnerRefused() error + func (p *Plugin) ResolveToken(ctx context.Context, t auth.Token) (auth.Principal, error) + func (p *Plugin) Revoke(ctx context.Context, id string) error + func (p *Plugin) SetLimits(ctx context.Context, id string, l Limits) error + func (p *Plugin) SetPermissions(ctx context.Context, id string, perms Permissions) error + func (p *Plugin) Sweep(ctx context.Context, cutoff time.Time) (int64, error) + func (p *Plugin) Tables() []sqlb.Table + func (p *Plugin) TokenPrefix() string + func (p *Plugin) TokenPrefixes() []string + func (p *Plugin) TypedMigrations(engine string, t auth.SQLTypes) ([]auth.Migration, error) + func (p *Plugin) Update(ctx context.Context, in UpdateRequest) (Key, error) + func (p *Plugin) UserTables() []auth.UserTable + func (p *Plugin) Validate(*auth.Config) error + func (p *Plugin) Verify(ctx context.Context, secret string, scopes ...string) (Verification, error) + func (p *Plugin) VerifyFor(ctx context.Context, config, secret string, scopes ...string) (Verification, error) + func (p *Plugin) VerifyPermissions(ctx context.Context, secret string, want Permissions) (Verification, error) + type RevokeRequest struct + Config string + ID string + type UpdateRequest struct + Config string + Disabled *bool + ExpiresIn *int64 + ExpiresInDays *int + ID string + Metadata json.RawMessage + Name *string + Scopes []string + type Verification struct + Key *Key + OrganizationID string + Reason error + UserID string + Valid bool + type Vocabulary map[string][]string + func Statements() Vocabulary + func (s Vocabulary) Check(p Permissions) error + func (s Vocabulary) Grants(granted, want Permissions) bool