access

package
v8.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 5 Imported by: 6 modules, 2 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

Index

Constants

View Source
const (
	// AccessProviderTypeConfigAPIKey is the built-in provider validating inline API keys.
	AccessProviderTypeConfigAPIKey = "config-api-key"

	// DefaultAccessProviderName is applied when no provider name is supplied.
	DefaultAccessProviderName = "config-inline"
)

Variables

This section is empty.

Functions

func ClearExclusiveProvider

func ClearExclusiveProvider()

ClearExclusiveProvider removes any active provider restriction.

func IsAuthErrorCode

func IsAuthErrorCode(authErr *AuthError, code AuthErrorCode) bool

func RegisterProvider

func RegisterProvider(typ string, provider Provider)

RegisterProvider registers a pre-built provider instance for a given type identifier.

func SetExclusiveProvider

func SetExclusiveProvider(typ string)

SetExclusiveProvider restricts RegisteredProviders to a single provider key when present.

func UnregisterProvider

func UnregisterProvider(typ string)

UnregisterProvider removes a provider by type identifier.

Types

type AccessConfig

type AccessConfig struct {
	// Providers lists configured authentication providers.
	Providers []AccessProvider `yaml:"providers,omitempty" json:"providers,omitempty"`
}

AccessConfig groups request authentication providers.

type AccessProvider

type AccessProvider struct {
	// Name is the instance identifier for the provider.
	Name string `yaml:"name" json:"name"`

	// Type selects the provider implementation registered via the SDK.
	Type string `yaml:"type" json:"type"`

	// SDK optionally names a third-party SDK module providing this provider.
	SDK string `yaml:"sdk,omitempty" json:"sdk,omitempty"`

	// APIKeys lists inline keys for providers that require them.
	APIKeys []string `yaml:"api-keys,omitempty" json:"api-keys,omitempty"`

	// Config passes provider-specific options to the implementation.
	Config map[string]any `yaml:"config,omitempty" json:"config,omitempty"`
}

AccessProvider describes a request authentication provider entry.

func MakeInlineAPIKeyProvider

func MakeInlineAPIKeyProvider(keys []string) *AccessProvider

MakeInlineAPIKeyProvider constructs an inline API key provider configuration. It returns nil when no keys are supplied.

type AuthError

type AuthError struct {
	Code       AuthErrorCode
	Message    string
	StatusCode int
	Cause      error
}

AuthError carries authentication failure details and HTTP status.

func NewDeniedError added in v8.0.39

func NewDeniedError(message string, statusCode int) *AuthError

func NewInternalAuthError

func NewInternalAuthError(message string, cause error) *AuthError

func NewInvalidCredentialError

func NewInvalidCredentialError() *AuthError

func NewNoCredentialsError

func NewNoCredentialsError() *AuthError

func NewNotHandledError

func NewNotHandledError() *AuthError

func NewRequestEntityTooLargeError added in v8.0.26

func NewRequestEntityTooLargeError(cause error) *AuthError

NewRequestEntityTooLargeError builds a 413 error when the request body exceeds the configured limit.

func (*AuthError) Error

func (e *AuthError) Error() string

func (*AuthError) HTTPStatusCode

func (e *AuthError) HTTPStatusCode() int

HTTPStatusCode returns a safe fallback for missing status codes.

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

type AuthErrorCode

type AuthErrorCode string

AuthErrorCode classifies authentication failures.

const (
	AuthErrorCodeNoCredentials     AuthErrorCode = "no_credentials"
	AuthErrorCodeInvalidCredential AuthErrorCode = "invalid_credential"
	AuthErrorCodeNotHandled        AuthErrorCode = "not_handled"
	AuthErrorCodeDenied            AuthErrorCode = "denied"
	AuthErrorCodeRequestTooLarge   AuthErrorCode = "request_too_large"
	AuthErrorCodeInternal          AuthErrorCode = "internal_error"
)

type Manager

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

Manager coordinates authentication providers.

func NewManager

func NewManager() *Manager

NewManager constructs an empty manager.

func (*Manager) Authenticate

func (m *Manager) Authenticate(ctx context.Context, r *http.Request) (*Result, *AuthError)

Authenticate evaluates providers until one succeeds.

func (*Manager) Providers

func (m *Manager) Providers() []Provider

Providers returns a snapshot of the active providers.

func (*Manager) SetProviders

func (m *Manager) SetProviders(providers []Provider)

SetProviders replaces the active provider list.

type Provider

type Provider interface {
	Identifier() string
	Authenticate(ctx context.Context, r *http.Request) (*Result, *AuthError)
}

Provider validates credentials for incoming requests.

func RegisteredProviders

func RegisteredProviders() []Provider

RegisteredProviders returns the global provider instances in registration order.

type Result

type Result struct {
	Provider  string
	Principal string
	Metadata  map[string]string
}

Result conveys authentication outcome.

Jump to

Keyboard shortcuts

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