auth

package
v0.0.2-beta.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
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) gin.HandlerFunc

NewAuthMiddleware creates a Gin 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) gin.HandlerFunc

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

type AccessControl interface {
	IsAllowed(role, resource string) bool
}

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

func WithAbortOnError(abort bool) Option

WithAbortOnError controls whether authentication failures should abort the request. When set to false, authentication errors are ignored and the request continues.

func WithAbortWithError

func WithAbortWithError(f func(ctx *gin.Context, err error)) Option

func WithCookieLoader

func WithCookieLoader(cookieName string) Option

func WithHeaderLoader

func WithHeaderLoader(header string) Option

func WithLoader

func WithLoader(f func(ctx *gin.Context) (string, error)) Option

func WithPrefixTransform

func WithPrefixTransform(prefix string) Option

func WithTransform

func WithTransform(f func(text string) (string, error)) Option

type PermissionOption

type PermissionOption func(*permissionOptions)

PermissionOption is a functional option for configuring permission middleware behavior.

func WithAbortForbidden

func WithAbortForbidden(fn func(ctx *gin.Context, status int, err error)) PermissionOption

WithAbortForbidden sets a custom error handler for permission denied scenarios.

Jump to

Keyboard shortcuts

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