Documentation
¶
Index ¶
- func Chain(middlewares ...func(http.Handler) http.Handler) func(http.Handler) http.Handler
- func ExtractBearerToken(r *http.Request) (string, error)
- func GetClaims(ctx context.Context) (*tokens.Claims, bool)
- func GetUserEmail(ctx context.Context) (string, bool)
- func GetUserID(ctx context.Context) (string, bool)
- func GetUserRoles(ctx context.Context) ([]string, bool)
- type AuthMiddleware
- func (m *AuthMiddleware) Authenticate(next http.Handler) http.Handler
- func (m *AuthMiddleware) RequireAnyRole(roleNames ...string) func(http.Handler) http.Handler
- func (m *AuthMiddleware) RequirePermission(permissionName string) func(http.Handler) http.Handler
- func (m *AuthMiddleware) RequireRole(roleName string) func(http.Handler) http.Handler
- type ContextKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractBearerToken ¶
ExtractBearerToken extracts the bearer token from the Authorization header
func GetUserEmail ¶
GetUserEmail extracts the user email from the request context
Types ¶
type AuthMiddleware ¶
type AuthMiddleware struct {
// contains filtered or unexported fields
}
AuthMiddleware is a middleware that validates JWT tokens
func NewAuthMiddleware ¶
func NewAuthMiddleware(service *auth.Service) *AuthMiddleware
NewAuthMiddleware creates a new auth middleware
func (*AuthMiddleware) Authenticate ¶
func (m *AuthMiddleware) Authenticate(next http.Handler) http.Handler
Authenticate returns a middleware that validates JWT tokens
func (*AuthMiddleware) RequireAnyRole ¶
RequireAnyRole returns a middleware that checks if the user has any of the specified roles
func (*AuthMiddleware) RequirePermission ¶
RequirePermission returns a middleware that checks if the user has a specific permission
func (*AuthMiddleware) RequireRole ¶
RequireRole returns a middleware that checks if the user has a specific role
type ContextKey ¶
type ContextKey string
ContextKey is the type for context keys
const ( // UserIDKey is the context key for user ID UserIDKey ContextKey = "user_id" // UserEmailKey is the context key for user email UserEmailKey ContextKey = "user_email" // UserRolesKey is the context key for user roles UserRolesKey ContextKey = "user_roles" // ClaimsKey is the context key for JWT claims ClaimsKey ContextKey = "claims" )
Click to show internal directories.
Click to hide internal directories.