Documentation
¶
Index ¶
- Constants
- func NewAuthMiddleware[T authorizer.UID, C authorizer.Claims[T]](parser authorizer.Parser[T, C], options ...Option) httpx.Middleware
- func NewPermissionMiddleware(resource string, acl AccessControl, options ...PermissionOption) httpx.Middleware
- type AccessControl
- type Option
- func WithAbortOnError(abort bool) Option
- func WithAbortWithError(f func(ctx httpx.Context, err error)) Option
- func WithCookieLoader(cookieName string) Option
- func WithHeaderLoader(header string) Option
- func WithLoader(f func(ctx httpx.Context) (string, error)) Option
- func WithPrefixTransform(prefix string) Option
- func WithTransform(f func(text string) (string, error)) Option
- type PermissionOption
Constants ¶
const ( // AuthorizationHeader is the standard HTTP header for authentication tokens. AuthorizationHeader = "Authorization" // AuthorizationPrefixBearer is the standard Bearer token prefix. AuthorizationPrefixBearer = "Bearer" )
Variables ¶
This section is empty.
Functions ¶
func NewAuthMiddleware ¶
func NewAuthMiddleware[T authorizer.UID, C authorizer.Claims[T]](parser authorizer.Parser[T, C], options ...Option) httpx.Middleware
NewAuthMiddleware creates middleware for JWT authentication. It parses tokens using the provided parser and sets authentication context. The middleware can be configured with various options for token loading and error handling.
func NewPermissionMiddleware ¶
func NewPermissionMiddleware(resource string, acl AccessControl, options ...PermissionOption) httpx.Middleware
NewPermissionMiddleware creates a role-based access control middleware. It checks if any of the user's roles have permission to access the specified resource using the provided AccessControl implementation.
Types ¶
type AccessControl ¶
AccessControl defines the interface for checking access permissions. Implementations should determine if a given role has access to a specific resource.
type Option ¶
type Option func(*options)
func WithAbortOnError ¶
WithAbortOnError controls whether authentication failures should abort the request. When set to false, authentication errors are ignored and the request continues.
func WithCookieLoader ¶
func WithHeaderLoader ¶
func WithPrefixTransform ¶
type PermissionOption ¶
type PermissionOption func(*permissionOptions)
PermissionOption is a functional option for configuring permission middleware behavior.
func WithAbortForbidden ¶
func WithAbortForbidden(fn func(ctx httpx.Context, status int, err error)) PermissionOption
WithAbortForbidden sets a custom error handler for permission denied scenarios.