authentications

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LookupEncodingNone          = "none"
	LookupEncodingBase64        = "base64"
	LookupEncodingBase64URLSafe = "base64urlsafe"
	LookupEncodingBase36        = "base36"
)
View Source
const (
	ExtractModeHeader     = "header"
	ExtractModeCookie     = "cookie"
	ExtractModeQuery      = "query"
	ExtractModePathSuffix = "path"
)

Variables

View Source
var AllBearerRedisTypes = []string{"string", "hash", "list", "set", "zset", "stream"}

Functions

func ConstructAuth added in v0.13.0

func ConstructAuth(rawConfig map[string]interface{}, deps authentication.AuthenticationDeps) (authentication.Authentication, error)

Types

type AuthWrapper added in v0.13.0

type AuthWrapper struct {
	Name string
	Auth authentication.Authentication
}

Adds tracing spans around every auth. Always used since OTEL no-ops when telemetry is disabled

func (AuthWrapper) CheckAuthentication added in v0.13.0

func (w AuthWrapper) CheckAuthentication(ctx context.Context, req *http.Request) bool

func (AuthWrapper) Close added in v0.13.0

func (w AuthWrapper) Close(ctx context.Context) error

Otherwise the wrapper would hide the inner auth's Closer from the shutdown path

type Bearer added in v0.13.0

type Bearer struct {
	BearerConfig
	// contains filtered or unexported fields
}

func (Bearer) CheckAuthentication added in v0.13.0

func (b Bearer) CheckAuthentication(ctx context.Context, req *http.Request) bool

func (Bearer) Close added in v0.13.0

func (b Bearer) Close(_ context.Context) error

type BearerConfig added in v0.13.0

type BearerConfig struct {
	Datastore     string                  // ID of a postgresql or redis datastore that holds the tokens. Required
	HeaderName    string                  // The header containing the token. If this is "Authorization" the "Bearer " prefix is required and removed. Defaults to "Authorization"
	TokenEncoding string                  // Encoding applied to the token before the lookup. One of AllLookupEncodings. Defaults to none
	CacheSize     int                     // How many lookup results to keep in memory. Zero or negative disables the cache, which is the default
	CacheTTL      uint32                  // Seconds a lookup result is reused, for both passing and failing tokens. Defaults to 600
	Postgresql    *BearerPostgresqlConfig // Required when Datastore is a postgresql datastore
	Redis         *BearerRedisConfig      // Only allowed when Datastore is a redis datastore
}

type BearerPostgresqlConfig added in v0.13.0

type BearerPostgresqlConfig struct {
	Query string // The token is bound to $1. Reads the valid, user_id, and tenant_id columns
}

type BearerRedisConfig added in v0.13.0

type BearerRedisConfig struct {
	KeyPrefix   string // Prepended to the token to form the key. Required
	UserField   string // The hash field holding the user ID. Defaults to "user"
	TenantField string // The hash field holding the tenant ID. Defaults to "tenant"
	AllowedType string // The key type accepted as a token. One of AllBearerRedisTypes. Defaults to any type
}

type BearerRegistration added in v0.13.0

type BearerRegistration struct {
}

func (BearerRegistration) Initialize added in v0.13.0

func (BearerRegistration) InitializeConfig added in v0.13.0

func (s BearerRegistration) InitializeConfig() any

func (BearerRegistration) Name added in v0.13.0

func (s BearerRegistration) Name() string

type Custom

type Custom struct {
	CustomConfig
	// contains filtered or unexported fields
}

func (Custom) CheckAuthentication

func (c Custom) CheckAuthentication(ctx context.Context, req *http.Request) bool

func (Custom) Close added in v0.11.0

func (c Custom) Close(ctx context.Context) error

The script's close function is optional so older scripts keep working

type CustomConfig

type CustomConfig struct {
	Token     map[string]string // How to extract the auth token from the request. Key should be one of the ExtractMode and Value is the specific identifier (or blank if inapplicable)
	CacheSize int               // Configures the size of the cache of already verified tokens to avoid re-verifying every request. Set to -1 to disable. Defaults to 100
	File      string            // Contains the go code to perform validation of the auth token as a file.
	Script    string            // Contains the go code to perform validation of the auth token inline.
}

type CustomRegistration

type CustomRegistration struct {
}

func (CustomRegistration) Initialize

func (CustomRegistration) InitializeConfig

func (s CustomRegistration) InitializeConfig() any

func (CustomRegistration) Name

func (s CustomRegistration) Name() string

type JWKSConfig added in v0.11.0

type JWKSConfig struct {
	URL                 string // The HTTPS URL of the JWKS endpoint. Required
	RefreshInterval     uint   // How many seconds between unconditional refreshes of the keyset. Defaults to 900
	RefreshMinInterval  uint   // The minimum seconds between refreshes triggered by an unknown key ID. Defaults to 60
	RequestTimeout      uint   // How many seconds before a fetch of the keyset is cancelled. Defaults to 10
	AllowStartupFailure bool   // If true, a failed fetch at startup logs a warning instead of preventing startup. Defaults to false
}

type JWT

type JWT struct {
	JWTConfig
	// contains filtered or unexported fields
}

func (JWT) CheckAuthentication

func (c JWT) CheckAuthentication(ctx context.Context, req *http.Request) bool

func (JWT) Close added in v0.11.0

func (c JWT) Close(ctx context.Context) error

Releases the caches and their background goroutines

type JWTConfig

type JWTConfig struct {
	CacheSize        uint16      // Configures the size of the cache of already verified JWTs to avoid re-verifying keys for every token. Expiration still applies. Set to 0 to disable. Defaults to 0
	Key              string      // The key for verifying the signature. The public key if using asymmetric signing. Required unless JWKS is supplied
	Algorithm        string      // Deprecated: use Algorithms. Retained so existing configurations keep working
	Algorithms       []string    // Algorithms to allow for JWT signatures. Required
	JWKS             *JWKSConfig // Fetch verification keys from a remote JWKS endpoint instead of Key
	HeaderName       string      // The header to extract the JWT from. If this is "Authorization" it removes the "Bearer " from the start. Defaults to "Authorization"
	MaxExpiration    uint32      // How many seconds from now can the expiration be. JWTs more than X seconds from now will result in a 401. Defaults to 1 day
	ExpectedAudience string      // If specified, require the "aud" grant to be this string
	ExpectedSubject  string      // If specified, require the "sub" grant to be this string
	ExpectedIssuer   string      // If specified, require the "iss" grant to be this string
	ExpectedScope    string      // If specified, require the "scope" grant to contain this string.
	LayerScope       bool        // If specified, the "scope" grant is used to limit access to layer
	ScopePrefix      string      // If LayerScope is true, this prefix indicates scopes to use
	UserID           string      // Use the specified grant as the user identifier. Defaults to sub
	TenantID         string      // Use the specified grant as the tenant identifier. Defaults to tid
}

type JWTRegistration

type JWTRegistration struct {
}

func (JWTRegistration) Initialize

func (JWTRegistration) InitializeConfig

func (s JWTRegistration) InitializeConfig() any

func (JWTRegistration) Name

func (s JWTRegistration) Name() string

type Noop

type Noop struct {
	NoopConfig
}

func (Noop) CheckAuthentication

func (c Noop) CheckAuthentication(_ context.Context, _ *http.Request) bool

type NoopConfig

type NoopConfig struct {
}

type NoopRegistration

type NoopRegistration struct {
}

func (NoopRegistration) Initialize

func (NoopRegistration) InitializeConfig

func (s NoopRegistration) InitializeConfig() any

func (NoopRegistration) Name

func (s NoopRegistration) Name() string

type Passthrough added in v0.13.0

type Passthrough struct {
	PassthroughConfig
	// contains filtered or unexported fields
}

func (Passthrough) CheckAuthentication added in v0.13.0

func (p Passthrough) CheckAuthentication(ctx context.Context, req *http.Request) bool

func (Passthrough) Close added in v0.13.0

func (p Passthrough) Close(_ context.Context) error

type PassthroughConfig added in v0.13.0

type PassthroughConfig struct {
	URL         string               // The endpoint to call. Required
	Method      string               // One of GET, HEAD, or POST. Defaults to GET
	Headers     []string             // Incoming headers to forward
	Cookies     []string             // Incoming cookies to forward
	QueryParams []string             // Incoming query parameters to forward
	UserID      string               // XPath to the user ID in the JSON or XML response body
	TenantID    string               // XPath to the tenant ID in the JSON or XML response body
	CacheSize   int                  // How many results to keep in memory. Zero or negative disables the cache, which is the default
	CacheTTL    uint32               // Seconds a result is reused. Defaults to 600
	Client      *config.ClientConfig // Overrides parameters of the top-level client
}

type PassthroughRegistration added in v0.13.0

type PassthroughRegistration struct {
}

func (PassthroughRegistration) Initialize added in v0.13.0

func (PassthroughRegistration) InitializeConfig added in v0.13.0

func (s PassthroughRegistration) InitializeConfig() any

func (PassthroughRegistration) Name added in v0.13.0

type StaticKey

type StaticKey struct {
	StaticKeyConfig
}

func (StaticKey) CheckAuthentication

func (c StaticKey) CheckAuthentication(_ context.Context, req *http.Request) bool

type StaticKeyConfig

type StaticKeyConfig struct {
	Key string
}

type StaticKeyRegistration

type StaticKeyRegistration struct {
}

func (StaticKeyRegistration) Initialize

func (StaticKeyRegistration) InitializeConfig

func (s StaticKeyRegistration) InitializeConfig() any

func (StaticKeyRegistration) Name

func (s StaticKeyRegistration) Name() string

Jump to

Keyboard shortcuts

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