auth

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(opts ...Option) middleware.Middleware

Auth 返回一个认证中间件

func FromContext

func FromContext(ctx context.Context) (any, bool)

FromContext 从上下文中提取认证信息

Types

type Context

type Context struct{}

Context 是身份验证上下文的键

type JWTValidator

type JWTValidator struct {
	Secret     string
	HeaderName string
}

JWTValidator 是JWT验证器

func NewJWTValidator

func NewJWTValidator(secret, headerName string) *JWTValidator

NewJWTValidator 创建一个新的JWT验证器

func (*JWTValidator) Validate

func (v *JWTValidator) Validate(ctx context.Context) (context.Context, error)

Validate 实现Validator接口

type Option

type Option func(*options)

Option 是认证中间件的选项

func WithValidator

func WithValidator(validator Validator) Option

WithValidator 设置令牌验证器

type Validator

type Validator interface {
	// Validate 验证认证信息并返回包含认证信息的上下文
	Validate(ctx context.Context) (context.Context, error)
}

Validator 是令牌验证器接口

Jump to

Keyboard shortcuts

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