auth

package
v1.0.0-feature-modules... Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// ContextKeyClaims is the gin context key for storing validated claims.
	ContextKeyClaims = "ws_claims"
)

Variables

This section is empty.

Functions

func ExtractTokenFromQuery

func ExtractTokenFromQuery(rawURL string) string

ExtractTokenFromQuery extracts a "token" query parameter from a URL.

func Middleware

func Middleware(jwtSecret string, authRequired bool) gin.HandlerFunc

Middleware returns a Gin handler that validates JWT tokens for WebSocket upgrade requests. It checks the Authorization header first, then falls back to the "token" query parameter.

func ValidateOrigin

func ValidateOrigin(origin string, allowedOrigins []string) bool

ValidateOrigin checks if a request origin is in the allowed origins list. An empty allowlist permits all origins.

Types

type Claims

type Claims struct {
	UserID   string
	TenantID string
	Raw      jwt.MapClaims
}

Claims holds the validated user claims from a JWT.

func GetClaims

func GetClaims(c *gin.Context) *Claims

GetClaims extracts the validated claims from the gin context.

func ValidateToken

func ValidateToken(token, secret string) (*Claims, error)

ValidateToken parses and validates a JWT, extracting userID and tenantID.

Jump to

Keyboard shortcuts

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