Documentation
¶
Index ¶
- func NewAPIKeyProvider(name string, opts ...APIKeyOption) auth.AuthProvider
- func NewBasicAuthProvider(name string, opts ...BasicAuthOption) auth.AuthProvider
- func NewBearerTokenProvider(name string, opts ...BearerTokenOption) auth.AuthProvider
- func NewOAuth2Provider(name string, flows *auth.OAuthFlows, opts ...OAuth2Option) auth.AuthProvider
- func NewOIDCProvider(name string, openIdConnectUrl string, opts ...OIDCOption) auth.AuthProvider
- type APIKeyOption
- func WithAPIKeyContainer(container forge.Container) APIKeyOption
- func WithAPIKeyCookie(name string) APIKeyOption
- func WithAPIKeyDescription(desc string) APIKeyOption
- func WithAPIKeyHeader(name string) APIKeyOption
- func WithAPIKeyQuery(param string) APIKeyOption
- func WithAPIKeyValidator(validator APIKeyValidator) APIKeyOption
- type APIKeyProvider
- func (p *APIKeyProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
- func (p *APIKeyProvider) Middleware() forge.Middleware
- func (p *APIKeyProvider) Name() string
- func (p *APIKeyProvider) OpenAPIScheme() auth.SecurityScheme
- func (p *APIKeyProvider) Type() auth.SecuritySchemeType
- type APIKeyValidator
- type BasicAuthOption
- type BasicAuthProvider
- func (p *BasicAuthProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
- func (p *BasicAuthProvider) Middleware() forge.Middleware
- func (p *BasicAuthProvider) Name() string
- func (p *BasicAuthProvider) OpenAPIScheme() auth.SecurityScheme
- func (p *BasicAuthProvider) Type() auth.SecuritySchemeType
- type BasicAuthValidator
- type BearerTokenOption
- type BearerTokenProvider
- func (p *BearerTokenProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
- func (p *BearerTokenProvider) Middleware() forge.Middleware
- func (p *BearerTokenProvider) Name() string
- func (p *BearerTokenProvider) OpenAPIScheme() auth.SecurityScheme
- func (p *BearerTokenProvider) Type() auth.SecuritySchemeType
- type BearerTokenValidator
- type LDAPConfig
- type LDAPProvider
- func (p *LDAPProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
- func (p *LDAPProvider) Close() error
- func (p *LDAPProvider) Middleware() forge.Middleware
- func (p *LDAPProvider) Name() string
- func (p *LDAPProvider) OpenAPIScheme() auth.SecurityScheme
- func (p *LDAPProvider) Type() auth.SecuritySchemeType
- type OAuth2Option
- type OAuth2Provider
- func (p *OAuth2Provider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
- func (p *OAuth2Provider) Middleware() forge.Middleware
- func (p *OAuth2Provider) Name() string
- func (p *OAuth2Provider) OpenAPIScheme() auth.SecurityScheme
- func (p *OAuth2Provider) Type() auth.SecuritySchemeType
- type OAuth2TokenValidator
- type OIDCOption
- type OIDCProvider
- func (p *OIDCProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
- func (p *OIDCProvider) Middleware() forge.Middleware
- func (p *OIDCProvider) Name() string
- func (p *OIDCProvider) OpenAPIScheme() auth.SecurityScheme
- func (p *OIDCProvider) Type() auth.SecuritySchemeType
- type OIDCTokenValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAPIKeyProvider ¶
func NewAPIKeyProvider(name string, opts ...APIKeyOption) auth.AuthProvider
NewAPIKeyProvider creates a new API key auth provider. By default, it looks for the API key in the "X-API-Key" header.
func NewBasicAuthProvider ¶
func NewBasicAuthProvider(name string, opts ...BasicAuthOption) auth.AuthProvider
NewBasicAuthProvider creates a new HTTP Basic Auth provider.
func NewBearerTokenProvider ¶
func NewBearerTokenProvider(name string, opts ...BearerTokenOption) auth.AuthProvider
NewBearerTokenProvider creates a new bearer token auth provider. By default, it expects JWT tokens.
func NewOAuth2Provider ¶
func NewOAuth2Provider(name string, flows *auth.OAuthFlows, opts ...OAuth2Option) auth.AuthProvider
NewOAuth2Provider creates a new OAuth2 auth provider.
func NewOIDCProvider ¶
func NewOIDCProvider(name string, openIdConnectUrl string, opts ...OIDCOption) auth.AuthProvider
NewOIDCProvider creates a new OpenID Connect auth provider.
Types ¶
type APIKeyOption ¶
type APIKeyOption func(*APIKeyProvider)
func WithAPIKeyContainer ¶
func WithAPIKeyContainer(container forge.Container) APIKeyOption
WithAPIKeyContainer sets the DI container (for accessing services)
func WithAPIKeyCookie ¶
func WithAPIKeyCookie(name string) APIKeyOption
WithAPIKeyCookie sets the cookie name to look for the API key
func WithAPIKeyDescription ¶
func WithAPIKeyDescription(desc string) APIKeyOption
WithAPIKeyDescription sets the OpenAPI description
func WithAPIKeyHeader ¶
func WithAPIKeyHeader(name string) APIKeyOption
WithAPIKeyHeader sets the header name to look for the API key
func WithAPIKeyQuery ¶
func WithAPIKeyQuery(param string) APIKeyOption
WithAPIKeyQuery sets the query parameter name to look for the API key
func WithAPIKeyValidator ¶
func WithAPIKeyValidator(validator APIKeyValidator) APIKeyOption
WithAPIKeyValidator sets the validator function
type APIKeyProvider ¶
type APIKeyProvider struct {
// contains filtered or unexported fields
}
APIKeyProvider implements API key authentication. API keys can be provided in headers, query parameters, or cookies.
func (*APIKeyProvider) Authenticate ¶
func (p *APIKeyProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
func (*APIKeyProvider) Middleware ¶
func (p *APIKeyProvider) Middleware() forge.Middleware
func (*APIKeyProvider) Name ¶
func (p *APIKeyProvider) Name() string
func (*APIKeyProvider) OpenAPIScheme ¶
func (p *APIKeyProvider) OpenAPIScheme() auth.SecurityScheme
func (*APIKeyProvider) Type ¶
func (p *APIKeyProvider) Type() auth.SecuritySchemeType
type APIKeyValidator ¶
APIKeyValidator validates an API key and returns the auth context. The validator has access to the DI container via the provider and can retrieve services like databases, caches, etc. for validation.
type BasicAuthOption ¶
type BasicAuthOption func(*BasicAuthProvider)
func WithBasicAuthContainer ¶
func WithBasicAuthContainer(container forge.Container) BasicAuthOption
WithBasicAuthContainer sets the DI container (for accessing services)
func WithBasicAuthDescription ¶
func WithBasicAuthDescription(desc string) BasicAuthOption
WithBasicAuthDescription sets the OpenAPI description
func WithBasicAuthValidator ¶
func WithBasicAuthValidator(validator BasicAuthValidator) BasicAuthOption
WithBasicAuthValidator sets the validator function
type BasicAuthProvider ¶
type BasicAuthProvider struct {
// contains filtered or unexported fields
}
BasicAuthProvider implements HTTP Basic Authentication. It extracts username and password from the Authorization header.
func (*BasicAuthProvider) Authenticate ¶
func (p *BasicAuthProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
func (*BasicAuthProvider) Middleware ¶
func (p *BasicAuthProvider) Middleware() forge.Middleware
func (*BasicAuthProvider) Name ¶
func (p *BasicAuthProvider) Name() string
func (*BasicAuthProvider) OpenAPIScheme ¶
func (p *BasicAuthProvider) OpenAPIScheme() auth.SecurityScheme
func (*BasicAuthProvider) Type ¶
func (p *BasicAuthProvider) Type() auth.SecuritySchemeType
type BasicAuthValidator ¶
type BasicAuthValidator func(ctx context.Context, username, password string) (*auth.AuthContext, error)
BasicAuthValidator validates username and password and returns the auth context. The validator can access services from the DI container to verify credentials against a database, LDAP, etc.
type BearerTokenOption ¶
type BearerTokenOption func(*BearerTokenProvider)
func WithBearerContainer ¶
func WithBearerContainer(container forge.Container) BearerTokenOption
WithBearerContainer sets the DI container (for accessing services)
func WithBearerDescription ¶
func WithBearerDescription(desc string) BearerTokenOption
WithBearerDescription sets the OpenAPI description
func WithBearerFormat ¶
func WithBearerFormat(format string) BearerTokenOption
WithBearerFormat sets the bearer token format (e.g., "JWT", "token")
func WithBearerValidator ¶
func WithBearerValidator(validator BearerTokenValidator) BearerTokenOption
WithBearerValidator sets the validator function
type BearerTokenProvider ¶
type BearerTokenProvider struct {
// contains filtered or unexported fields
}
BearerTokenProvider implements Bearer token authentication (JWT, OAuth2, etc.). It extracts tokens from the Authorization header using the "Bearer" scheme.
func (*BearerTokenProvider) Authenticate ¶
func (p *BearerTokenProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
func (*BearerTokenProvider) Middleware ¶
func (p *BearerTokenProvider) Middleware() forge.Middleware
func (*BearerTokenProvider) Name ¶
func (p *BearerTokenProvider) Name() string
func (*BearerTokenProvider) OpenAPIScheme ¶
func (p *BearerTokenProvider) OpenAPIScheme() auth.SecurityScheme
func (*BearerTokenProvider) Type ¶
func (p *BearerTokenProvider) Type() auth.SecuritySchemeType
type BearerTokenValidator ¶
BearerTokenValidator validates a bearer token and returns the auth context. The validator can access services from the DI container for JWT verification, token introspection, etc.
type LDAPConfig ¶ added in v0.4.0
type LDAPConfig struct {
// Connection settings
Host string `yaml:"host" json:"host"`
Port int `yaml:"port" json:"port"`
// Bind credentials (service account)
BindDN string `yaml:"bind_dn" json:"bind_dn"`
BindPassword string `yaml:"bind_password" json:"bind_password"`
// Search settings
BaseDN string `yaml:"base_dn" json:"base_dn"`
SearchFilter string `yaml:"search_filter" json:"search_filter"` // e.g., "(uid=%s)" or "(sAMAccountName=%s)"
Attributes []string `yaml:"attributes" json:"attributes"` // Attributes to fetch
// TLS settings
UseTLS bool `yaml:"use_tls" json:"use_tls"`
InsecureSkipVerify bool `yaml:"insecure_skip_verify" json:"insecure_skip_verify"`
// Connection pool
PoolSize int `yaml:"pool_size" json:"pool_size"`
ConnectionTimeout time.Duration `yaml:"connection_timeout" json:"connection_timeout"`
RequestTimeout time.Duration `yaml:"request_timeout" json:"request_timeout"`
IdleTimeout time.Duration `yaml:"idle_timeout" json:"idle_timeout"`
MaxRetries int `yaml:"max_retries" json:"max_retries"`
RetryDelay time.Duration `yaml:"retry_delay" json:"retry_delay"`
// Cache settings
EnableCache bool `yaml:"enable_cache" json:"enable_cache"`
CacheTTL time.Duration `yaml:"cache_ttl" json:"cache_ttl"`
// Group mapping
GroupBaseDN string `yaml:"group_base_dn" json:"group_base_dn"` // e.g., "ou=groups,dc=company,dc=com"
GroupFilter string `yaml:"group_filter" json:"group_filter"` // e.g., "(member=%s)"
RoleMapping map[string]string `yaml:"role_mapping" json:"role_mapping"` // LDAP group DN -> app role
// Advanced
EnableReferrals bool `yaml:"enable_referrals" json:"enable_referrals"` // Handle AD referrals
PageSize int `yaml:"page_size" json:"page_size"` // Paging for large result sets
}
LDAPConfig holds LDAP/Active Directory configuration
func DefaultLDAPConfig ¶ added in v0.4.0
func DefaultLDAPConfig() LDAPConfig
DefaultLDAPConfig returns default LDAP configuration
type LDAPProvider ¶ added in v0.4.0
type LDAPProvider struct {
// contains filtered or unexported fields
}
LDAPProvider implements LDAP/Active Directory authentication
func NewLDAPProvider ¶ added in v0.4.0
func NewLDAPProvider(config LDAPConfig, logger forge.Logger) (*LDAPProvider, error)
NewLDAPProvider creates a new LDAP authentication provider
func (*LDAPProvider) Authenticate ¶ added in v0.4.0
func (p *LDAPProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
Authenticate authenticates a user against LDAP/AD
func (*LDAPProvider) Close ¶ added in v0.4.0
func (p *LDAPProvider) Close() error
Close closes the LDAP connection pool
func (*LDAPProvider) Middleware ¶ added in v0.4.0
func (p *LDAPProvider) Middleware() forge.Middleware
Middleware returns the authentication middleware
func (*LDAPProvider) Name ¶ added in v0.4.0
func (p *LDAPProvider) Name() string
Name returns the provider name
func (*LDAPProvider) OpenAPIScheme ¶ added in v0.4.0
func (p *LDAPProvider) OpenAPIScheme() auth.SecurityScheme
OpenAPIScheme returns the OpenAPI security scheme
func (*LDAPProvider) Type ¶ added in v0.4.0
func (p *LDAPProvider) Type() auth.SecuritySchemeType
Type returns the security scheme type
type OAuth2Option ¶
type OAuth2Option func(*OAuth2Provider)
func WithOAuth2Container ¶
func WithOAuth2Container(container forge.Container) OAuth2Option
WithOAuth2Container sets the DI container (for accessing services)
func WithOAuth2Description ¶
func WithOAuth2Description(desc string) OAuth2Option
WithOAuth2Description sets the OpenAPI description
func WithOAuth2Validator ¶
func WithOAuth2Validator(validator OAuth2TokenValidator) OAuth2Option
WithOAuth2Validator sets the validator function
type OAuth2Provider ¶
type OAuth2Provider struct {
// contains filtered or unexported fields
}
OAuth2Provider implements OAuth 2.0 authentication. It validates OAuth2 access tokens and extracts scopes and permissions.
func (*OAuth2Provider) Authenticate ¶
func (p *OAuth2Provider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
func (*OAuth2Provider) Middleware ¶
func (p *OAuth2Provider) Middleware() forge.Middleware
func (*OAuth2Provider) Name ¶
func (p *OAuth2Provider) Name() string
func (*OAuth2Provider) OpenAPIScheme ¶
func (p *OAuth2Provider) OpenAPIScheme() auth.SecurityScheme
func (*OAuth2Provider) Type ¶
func (p *OAuth2Provider) Type() auth.SecuritySchemeType
type OAuth2TokenValidator ¶
OAuth2TokenValidator validates an OAuth2 token and returns the auth context. The validator should verify the token with the OAuth2 authorization server and extract claims, scopes, etc.
type OIDCOption ¶
type OIDCOption func(*OIDCProvider)
func WithOIDCContainer ¶
func WithOIDCContainer(container forge.Container) OIDCOption
WithOIDCContainer sets the DI container (for accessing services)
func WithOIDCDescription ¶
func WithOIDCDescription(desc string) OIDCOption
WithOIDCDescription sets the OpenAPI description
func WithOIDCValidator ¶
func WithOIDCValidator(validator OIDCTokenValidator) OIDCOption
WithOIDCValidator sets the validator function
type OIDCProvider ¶
type OIDCProvider struct {
// contains filtered or unexported fields
}
OIDCProvider implements OpenID Connect authentication. It validates OIDC ID tokens and access tokens.
func (*OIDCProvider) Authenticate ¶
func (p *OIDCProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)
func (*OIDCProvider) Middleware ¶
func (p *OIDCProvider) Middleware() forge.Middleware
func (*OIDCProvider) Name ¶
func (p *OIDCProvider) Name() string
func (*OIDCProvider) OpenAPIScheme ¶
func (p *OIDCProvider) OpenAPIScheme() auth.SecurityScheme
func (*OIDCProvider) Type ¶
func (p *OIDCProvider) Type() auth.SecuritySchemeType
type OIDCTokenValidator ¶
OIDCTokenValidator validates an OIDC token and returns the auth context. The validator should verify the token with the OIDC provider and extract claims (sub, email, name, etc.).