Documentation
¶
Index ¶
- func APIKeyMiddleware(validator AuthorizationService, scheme SecurityScheme) fiber.Handler
- func AWSSignatureMiddleware(validator AuthorizationService) fiber.Handler
- func BasicAuthMiddleware(validator AuthorizationService) fiber.Handler
- func BearerTokenMiddleware(validator AuthorizationService) fiber.Handler
- func ConditionalAuthMiddleware(authMiddleware fiber.Handler, excludePaths ...string) fiber.Handler
- func Delete[TInput any, TOutput any, TError any](router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], ...)
- func Get[TInput any, TOutput any, TError any](router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], ...)
- func Head[TInput any, TOutput any, TError any](router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], ...)
- func Method[TInput any, TOutput any, TError any](router OApiRouter, m string, path string, ...)
- func MultiSchemeAuthMiddleware(authService AuthorizationService, config Config) fiber.Handler
- func Patch[TInput any, TOutput any, TError any](router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], ...)
- func Post[TInput any, TOutput any, TError any](router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], ...)
- func Put[TInput any, TOutput any, TError any](router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], ...)
- func RequireResourceAccess(c *fiber.Ctx, authService AuthorizationService, ...) error
- func RoleGuard(validator AuthorizationService, requiredRoles ...string) fiber.Handler
- func SmartAuthMiddleware(authService AuthorizationService, config Config) fiber.Handler
- type APIKeyValidator
- type AWSSignatureParams
- type AWSSignatureValidator
- type AuthContext
- type AuthError
- type AuthErrorHandler
- type AuthorizationService
- type BasicAuthValidator
- type Config
- type DocConfig
- type ErrorResponse
- type HandlerFunc
- type OApiApp
- func (o *OApiApp) Config() Config
- func (o *OApiApp) GenerateOpenAPISpec() map[string]interface{}
- func (o *OApiApp) GenerateOpenAPISpecYAML() (string, error)
- func (o *OApiApp) GetApp() *OApiApp
- func (o *OApiApp) GetOperations() []OpenAPIOperation
- func (o *OApiApp) GetPrefix() string
- func (app *OApiApp) Group(prefix string, handlers ...fiber.Handler) *OApiGroup
- func (o *OApiApp) Listen(addr string) error
- func (o *OApiApp) SetupDocs(config ...DocConfig)
- func (o *OApiApp) Use(middleware fiber.Handler)
- type OApiGroup
- type OApiRouter
- type OpenAPIOperation
- type OpenAPIOptions
- func WithAllRoles(options OpenAPIOptions, roles ...string) OpenAPIOptions
- func WithPermissions(options OpenAPIOptions, permissions ...string) OpenAPIOptions
- func WithResourceType(options OpenAPIOptions, resourceType string) OpenAPIOptions
- func WithRoles(options OpenAPIOptions, roles ...string) OpenAPIOptions
- func WithSecurity(options OpenAPIOptions, security interface{}) OpenAPIOptions
- func WithSecurityDisabled(options OpenAPIOptions) OpenAPIOptions
- type OpenAPIParameter
- type OpenAPIRequestBody
- type OpenAPIResponse
- type PathInfo
- type ResourcePermission
- type ScopeError
- type SecurityScheme
- type ValidationErrorHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIKeyMiddleware ¶ added in v1.8.0
func APIKeyMiddleware(validator AuthorizationService, scheme SecurityScheme) fiber.Handler
APIKeyMiddleware creates a standalone middleware for API Key authentication. The authService must implement the APIKeyValidator interface.
func AWSSignatureMiddleware ¶ added in v1.8.0
func AWSSignatureMiddleware(validator AuthorizationService) fiber.Handler
AWSSignatureMiddleware creates a standalone middleware for AWS Signature V4 authentication. The authService must implement the AWSSignatureValidator interface.
func BasicAuthMiddleware ¶ added in v1.8.0
func BasicAuthMiddleware(validator AuthorizationService) fiber.Handler
BasicAuthMiddleware creates a standalone middleware for HTTP Basic authentication. The authService must implement the BasicAuthValidator interface.
func BearerTokenMiddleware ¶ added in v1.4.0
func BearerTokenMiddleware(validator AuthorizationService) fiber.Handler
BearerTokenMiddleware creates a JWT/Bearer middleware
func ConditionalAuthMiddleware ¶ added in v1.4.0
ConditionalAuthMiddleware creates middleware that applies only to specified routes
func Delete ¶ added in v1.2.0
func Delete[TInput any, TOutput any, TError any]( router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], options OpenAPIOptions, )
Delete defines a DELETE operation for the OpenAPI documentation
func Get ¶ added in v1.2.0
func Get[TInput any, TOutput any, TError any]( router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], options OpenAPIOptions, )
Get defines a GET operation for the OpenAPI documentation
func Head ¶ added in v1.2.0
func Head[TInput any, TOutput any, TError any]( router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], options OpenAPIOptions, )
Head defines a HEAD operation for the OpenAPI documentation
func Method ¶ added in v1.2.0
func Method[TInput any, TOutput any, TError any]( router OApiRouter, m string, path string, handler HandlerFunc[TInput, TOutput, TError], options OpenAPIOptions, )
Method defines a generic method for registering HTTP operations with OpenAPI documentation
func MultiSchemeAuthMiddleware ¶ added in v1.8.0
func MultiSchemeAuthMiddleware(authService AuthorizationService, config Config) fiber.Handler
MultiSchemeAuthMiddleware creates middleware that tries configured security schemes. It iterates over DefaultSecurity requirements (OR semantics) and validates using the appropriate scheme handler.
func Patch ¶ added in v1.2.0
func Patch[TInput any, TOutput any, TError any]( router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], options OpenAPIOptions, )
Patch defines a PATCH operation for the OpenAPI documentation
func Post ¶ added in v1.2.0
func Post[TInput any, TOutput any, TError any]( router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], options OpenAPIOptions, )
Post defines a POST operation for the OpenAPI documentation
func Put ¶ added in v1.2.0
func Put[TInput any, TOutput any, TError any]( router OApiRouter, path string, handler HandlerFunc[TInput, TOutput, TError], options OpenAPIOptions, )
Put defines a PUT operation for the OpenAPI documentation
func RequireResourceAccess ¶ added in v1.4.0
func RequireResourceAccess(c *fiber.Ctx, authService AuthorizationService, resourceType, resourceID, action string) error
RequireResourceAccess checks permissions in handlers
func RoleGuard ¶ added in v1.4.0
func RoleGuard(validator AuthorizationService, requiredRoles ...string) fiber.Handler
RoleGuard middleware for role verification
func SmartAuthMiddleware ¶ added in v1.4.0
func SmartAuthMiddleware(authService AuthorizationService, config Config) fiber.Handler
SmartAuthMiddleware creates middleware that automatically excludes documentation routes. When SecuritySchemes are configured, it uses MultiSchemeAuthMiddleware for dispatch. Otherwise, it falls back to BearerTokenMiddleware for backward compatibility.
Types ¶
type APIKeyValidator ¶ added in v1.8.0
type APIKeyValidator interface {
ValidateAPIKey(key string, location string, paramName string) (*AuthContext, error)
}
APIKeyValidator is an optional interface for services that support API Key authentication (in header, query, or cookie).
type AWSSignatureParams ¶ added in v1.8.0
type AWSSignatureParams struct {
// Parsed from "Credential=AKID/date/region/service/aws4_request"
AccessKeyID string
Date string
Region string
Service string
// Parsed from "SignedHeaders=host;x-amz-date;..."
SignedHeaders []string
// The raw signature hex string
Signature string
// The raw Authorization header for custom verification
RawHeader string
// Request metadata needed for signature verification
Method string
Path string
QueryString string
Headers map[string]string
Body []byte
}
AWSSignatureParams contains the parsed components of an AWS SigV4 Authorization header.
type AWSSignatureValidator ¶ added in v1.8.0
type AWSSignatureValidator interface {
ValidateAWSSignature(params *AWSSignatureParams) (*AuthContext, error)
}
AWSSignatureValidator is an optional interface for services that support AWS Signature V4 authentication. The library parses the Authorization header and passes structured data; the implementation handles the actual cryptographic verification.
type AuthContext ¶ added in v1.4.0
type AuthContext struct {
UserID string `json:"user_id"`
Roles []string `json:"roles"`
Scopes []string `json:"scopes"`
Claims map[string]interface{} `json:"claims"`
}
AuthContext contains user authentication details
func GetAuthContext ¶ added in v1.4.0
func GetAuthContext(c *fiber.Ctx) (*AuthContext, error)
GetAuthContext extracts the authentication context from Fiber
type AuthError ¶ added in v1.8.0
AuthError represents an authentication or authorization failure with an HTTP status code.
type AuthErrorHandler ¶ added in v1.9.1
AuthErrorHandler is a function type for handling authentication/authorization errors It receives the fiber context and the AuthError, and returns a fiber error response
type AuthorizationService ¶ added in v1.4.0
type AuthorizationService interface {
// Authentication
ValidateToken(token string) (*AuthContext, error)
// Global authorization (roles/scopes)
HasRole(ctx *AuthContext, role string) bool
HasScope(ctx *AuthContext, scope string) bool
// Dynamic authorization on resources
CanAccessResource(ctx *AuthContext, resourceType, resourceID, action string) (bool, error)
GetUserPermissions(ctx *AuthContext, resourceType, resourceID string) (*ResourcePermission, error)
}
AuthorizationService interface for permission checks
type BasicAuthValidator ¶ added in v1.8.0
type BasicAuthValidator interface {
ValidateBasicAuth(username, password string) (*AuthContext, error)
}
BasicAuthValidator is an optional interface for services that support HTTP Basic authentication. Implement this alongside AuthorizationService to enable Basic Auth validation.
type Config ¶
type Config struct {
EnableValidation bool // Enable request validation (default: true)
EnableOpenAPIDocs bool // Enable automatic docs setup (default: true)
EnableAuthorization bool // Enable authorization validation (default: false)
OpenAPIDocsPath string // Path for documentation UI (default: "/docs")
OpenAPIJSONPath string // Path for OpenAPI JSON spec (default: "/openapi.json")
OpenAPIYamlPath string // Path for OpenAPI YAML spec (default: "/openapi.yaml")
AuthService AuthorizationService // Service for handling authentication and authorization
SecuritySchemes map[string]SecurityScheme // OpenAPI security schemes
DefaultSecurity []map[string][]string // Default security requirements
ValidationErrorHandler ValidationErrorHandler // Custom handler for validation errors
AuthErrorHandler AuthErrorHandler // Custom handler for auth errors (401/403/5xx)
}
Config represents configuration for the OApi wrapper
type DocConfig ¶
type DocConfig struct {
Title string
Description string
Version string
DocsPath string // Path where docs will be served, default: "/docs"
JSONPath string // Path where OpenAPI JSON will be served, default: "/openapi.json"
YamlPath string // Path where OpenAPI YAML will be served, default: "/openapi.yaml"
}
DocConfig contains configuration for the documentation
func DefaultDocConfig ¶
func DefaultDocConfig() DocConfig
DefaultDocConfig returns default documentation configuration
type ErrorResponse ¶ added in v1.3.0
type HandlerFunc ¶
type HandlerFunc[TInput any, TOutput any, TError any] func(c *fiber.Ctx, input TInput) (TOutput, TError)
HandlerFunc represents a handler function with typed input and output
type OApiApp ¶
type OApiApp struct {
// contains filtered or unexported fields
}
OApiApp wraps fiber.App with OpenAPI capabilities
func (*OApiApp) GenerateOpenAPISpec ¶
GenerateOpenAPISpec generates a complete OpenAPI 3.0 specification
func (*OApiApp) GenerateOpenAPISpecYAML ¶ added in v1.5.0
GenerateOpenAPISpecYAML generates the OpenAPI spec in YAML format
func (*OApiApp) GetOperations ¶
func (o *OApiApp) GetOperations() []OpenAPIOperation
GetOperations returns all registered operations (useful for testing and documentation generation)
type OApiGroup ¶ added in v1.2.0
type OApiGroup struct {
fiber.Router // Embedded fiber.Router (includes all standard Fiber methods)
// contains filtered or unexported fields
}
OApiGroup wraps a fiber.Router and adds OpenAPI methods
func Group ¶ added in v1.2.0
func Group(router OApiRouter, prefix string, handlers ...fiber.Handler) *OApiGroup
Group creates a new group from an OApiRouter (app or group)
type OApiRouter ¶ added in v1.2.0
OApiRouter interface that both OApiApp and OApiGroup implement
type OpenAPIOperation ¶
type OpenAPIOperation struct {
Method string
Path string
Options OpenAPIOptions
InputType reflect.Type
OutputType reflect.Type
ErrorType reflect.Type
}
OpenAPIOperation represents a registered operation
type OpenAPIOptions ¶
type OpenAPIOptions struct {
OperationID string `json:"operationId,omitempty"`
Tags []string `json:"tags,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Parameters []map[string]any `json:"parameters,omitempty"`
Security any `json:"security,omitempty"` // Can be []map[string][]string or "disabled"
RequiredRoles []string `json:"-"` // Roles required to access this route (OR semantics by default)
RequireAllRoles bool `json:"-"` // If true, all RequiredRoles must match (AND semantics)
RequiredPermissions []string `json:"-"` // Ex: ["document:read", "workspace:admin"]
ResourceType string `json:"-"` // Type de ressource concernée
}
OpenAPIOptions represents options for OpenAPI operations
func WithAllRoles ¶ added in v1.9.2
func WithAllRoles(options OpenAPIOptions, roles ...string) OpenAPIOptions
WithAllRoles adds required roles to a route with AND semantics (user needs all of them)
func WithPermissions ¶ added in v1.4.0
func WithPermissions(options OpenAPIOptions, permissions ...string) OpenAPIOptions
WithPermissions adds required permissions for documentation
func WithResourceType ¶ added in v1.4.0
func WithResourceType(options OpenAPIOptions, resourceType string) OpenAPIOptions
WithResourceType defines the concerned resource type
func WithRoles ¶ added in v1.9.0
func WithRoles(options OpenAPIOptions, roles ...string) OpenAPIOptions
WithRoles adds required roles to a route with OR semantics (user needs at least one)
func WithSecurity ¶ added in v1.4.0
func WithSecurity(options OpenAPIOptions, security interface{}) OpenAPIOptions
WithSecurity adds security to a route
func WithSecurityDisabled ¶ added in v1.4.0
func WithSecurityDisabled(options OpenAPIOptions) OpenAPIOptions
WithSecurityDisabled disables security for a route
type OpenAPIParameter ¶
type OpenAPIRequestBody ¶
type OpenAPIResponse ¶
type ResourcePermission ¶ added in v1.4.0
type ResourcePermission struct {
ResourceType string `json:"resource_type"`
ResourceID string `json:"resource_id"`
Actions []string `json:"actions"` // ["read", "write", "delete", "share"]
}
ResourcePermission defines permissions on a resource
type ScopeError ¶ added in v1.8.0
type ScopeError struct {
Scope string
}
ScopeError represents an authorization failure due to missing scopes (403, not 401).
func (*ScopeError) Error ¶ added in v1.8.0
func (e *ScopeError) Error() string
type SecurityScheme ¶ added in v1.4.0
type SecurityScheme struct {
Type string `json:"type" yaml:"type"`
Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"`
BearerFormat string `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
In string `json:"in,omitempty" yaml:"in,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Flows map[string]interface{} `json:"flows,omitempty" yaml:"flows,omitempty"`
}
SecurityScheme for OpenAPI