middleware

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UserContextKey 用户上下文键
	UserContextKey contextKey = "auth_user"

	// TokenContextKey 令牌上下文键
	TokenContextKey contextKey = "auth_token"
)

Variables

This section is empty.

Functions

func GetAuthenticatedUser

func GetAuthenticatedUser(ctx context.Context) (auth.Authenticatable, bool)

GetAuthenticatedUser 获取认证用户

func GetToken

func GetToken(ctx context.Context) (string, bool)

GetToken 获取认证令牌

Types

type JWTMiddleware

type JWTMiddleware struct {
	// contains filtered or unexported fields
}

JWTMiddleware JWT认证中间件

func NewJWTMiddleware

func NewJWTMiddleware(options Options) *JWTMiddleware

NewJWTMiddleware 创建新的JWT中间件

func (*JWTMiddleware) Middleware

func (m *JWTMiddleware) Middleware() func(http.Handler) http.Handler

Middleware 返回HTTP中间件函数

func (*JWTMiddleware) RequirePermission

func (m *JWTMiddleware) RequirePermission(permission string) func(http.Handler) http.Handler

RequirePermission 创建权限检查中间件

func (*JWTMiddleware) RequireRole

func (m *JWTMiddleware) RequireRole(role string) func(http.Handler) http.Handler

RequireRole 创建角色检查中间件

type Options

type Options struct {
	// Provider 认证提供者
	Provider auth.Provider

	// TokenLookup 令牌查找位置,格式: "header:Authorization,query:token,cookie:jwt"
	TokenLookup string

	// AuthScheme 认证方案,例如: "Bearer"
	AuthScheme string

	// SkipRoutes 跳过认证的路由
	SkipRoutes []string
}

Options JWT中间件配置选项

func DefaultOptions

func DefaultOptions() Options

DefaultOptions 返回默认中间件选项

Jump to

Keyboard shortcuts

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