access

package
v6.8.9 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 5 Imported by: 0

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 IsAuthErrorCode added in v6.8.9

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 UnregisterProvider added in v6.8.9

func UnregisterProvider(typ string)

UnregisterProvider removes a provider by type identifier.

Types

type AccessConfig added in v6.8.9

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

AccessConfig groups request authentication providers.

type AccessProvider added in v6.8.9

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 added in v6.8.9

func MakeInlineAPIKeyProvider(keys []string) *AccessProvider

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

type AuthError added in v6.8.9

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

AuthError carries authentication failure details and HTTP status.

func NewInternalAuthError added in v6.8.9

func NewInternalAuthError(message string, cause error) *AuthError

func NewInvalidCredentialError added in v6.8.9

func NewInvalidCredentialError() *AuthError

func NewNoCredentialsError added in v6.8.9

func NewNoCredentialsError() *AuthError

func NewNotHandledError added in v6.8.9

func NewNotHandledError() *AuthError

func (*AuthError) Error added in v6.8.9

func (e *AuthError) Error() string

func (*AuthError) HTTPStatusCode added in v6.8.9

func (e *AuthError) HTTPStatusCode() int

HTTPStatusCode returns a safe fallback for missing status codes.

func (*AuthError) Unwrap added in v6.8.9

func (e *AuthError) Unwrap() error

type AuthErrorCode added in v6.8.9

type AuthErrorCode string

AuthErrorCode classifies authentication failures.

const (
	AuthErrorCodeNoCredentials     AuthErrorCode = "no_credentials"
	AuthErrorCodeInvalidCredential AuthErrorCode = "invalid_credential"
	AuthErrorCodeNotHandled        AuthErrorCode = "not_handled"
	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 added in v6.8.9

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