authcache

package
v3.42.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package authcache implements a cache for token auth to hold auth- results with cpu/mem inexpensive methods instead of always using secure but expensive methods to validate the token

Index

Constants

View Source
const AuthBackendAny = "*"

AuthBackendAny signals any backend can answer the validity of the token and no specific backend is selected

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized")

ErrUnauthorized denotes the token could not be found in any backend auth method and therefore is not an user

Functions

This section is empty.

Types

type AuthFunc

type AuthFunc func(token string) (modules []string, expiresAt time.Time, err error)

AuthFunc is a backend-function to resolve a token to a list of modules the token is authorized for, an expiry-time and an error. The error MUST be ErrUnauthorized in case the user is not found, if the error is another, the backend resolve will be cancelled and no further backends are queried.

type CacheEntry

type CacheEntry struct {
	AuthResult error // Allows for negative caching
	ExpiresAt  time.Time
	Modules    []string
}

CacheEntry represents an entry in the cache Service

type CreateOpt added in v3.40.0

type CreateOpt func(*Service)

CreateOpt supplies options to the creation of the cache

func WithAuthBackend added in v3.40.0

func WithAuthBackend(name string, fn AuthFunc) CreateOpt

WithAuthBackend adds a new auth backend which is tried in order of begin added

type Service

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

Service manages the cached auth results

func New

func New(fns ...CreateOpt) *Service

New creates a new Service with the given backend methods to authenticate users

func (*Service) ValidateTokenFor

func (s *Service) ValidateTokenFor(token string, modules ...string) error

ValidateTokenFor checks backends whether the given token has access to the given modules and caches the result

func (*Service) ValidateTokenForWithTokenType added in v3.40.0

func (s *Service) ValidateTokenForWithTokenType(token string, authBackendName string, modules ...string) error

ValidateTokenForWithTokenType checks the configured backends whether the given token has access to the given modules and caches the result for the selected auth backend name.

Jump to

Keyboard shortcuts

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