auth

package
v0.0.0-...-07920c1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAuthFileSystem

func GetAuthFileSystem() http.FileSystem

GetAuthFileSystem 返回认证页面的文件系统

func GetFileContent

func GetFileContent(filename string) (string, error)

GetFileContent 从嵌入式文件系统中读取文件内容

func GetLoginHTMLContent

func GetLoginHTMLContent() (string, error)

GetLoginHTMLContent 获取登录页面的HTML内容

Types

type AuthType

type AuthType string

AuthType 表示认证类型

const (
	// NoAuth 表示不使用认证
	NoAuth AuthType = "none"
	// BasicAuth 表示使用HTTP Basic认证
	BasicAuth AuthType = "basic"
	// TokenAuth 表示使用令牌认证
	TokenAuth AuthType = "token"
	// FormAuth 表示使用表单认证(登录页面)
	FormAuth AuthType = "form"
)

type Authenticator

type Authenticator interface {
	// Middleware 返回一个Gin中间件,用于处理认证
	Middleware() gin.HandlerFunc
	// AuthType 返回认证类型
	AuthType() AuthType
	// LoginPageEnabled 返回是否启用了登录页
	LoginPageEnabled() bool
	// GetCredentials 返回认证凭据
	GetCredentials() (username, password string)
}

Authenticator 接口定义了认证器的方法

func NewAuthenticator

func NewAuthenticator(config Config) Authenticator

NewAuthenticator 根据配置创建一个认证器

type BasicAuthenticator

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

BasicAuthenticator 实现了HTTP Basic认证

func NewBasicAuth

func NewBasicAuth(config Config) *BasicAuthenticator

NewBasicAuth 创建一个BasicAuth认证器

func (*BasicAuthenticator) AuthType

func (a *BasicAuthenticator) AuthType() AuthType

AuthType 返回认证类型

func (*BasicAuthenticator) GetCredentials

func (a *BasicAuthenticator) GetCredentials() (username, password string)

GetCredentials 返回认证凭据

func (*BasicAuthenticator) LoginPageEnabled

func (a *BasicAuthenticator) LoginPageEnabled() bool

LoginPageEnabled 返回是否启用了登录页

func (*BasicAuthenticator) Middleware

func (a *BasicAuthenticator) Middleware() gin.HandlerFunc

Middleware 返回Gin的Basic认证中间件

type Config

type Config struct {
	// AuthType 认证类型
	Type AuthType
	// Username 用户名,用于BasicAuth和FormAuth
	Username string
	// Password 密码,用于BasicAuth和FormAuth
	Password string
	// Token 令牌,用于TokenAuth
	Token string
	// EnableLoginPage 是否启用登录页面
	EnableLoginPage bool
	// Realm 认证域,用于BasicAuth
	Realm string
}

Config 保存认证配置

func (*Config) GetGlobalConfig

func (c *Config) GetGlobalConfig() config.Config

GetGlobalConfig 获取全局配置

type FormAuthenticator

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

FormAuthenticator 实现了基于表单的认证

func NewFormAuth

func NewFormAuth(config Config) *FormAuthenticator

NewFormAuth 创建一个FormAuth认证器

func (*FormAuthenticator) AuthType

func (a *FormAuthenticator) AuthType() AuthType

AuthType 返回认证类型

func (*FormAuthenticator) GetCredentials

func (a *FormAuthenticator) GetCredentials() (username, password string)

GetCredentials 返回认证凭据

func (*FormAuthenticator) LoginPageEnabled

func (a *FormAuthenticator) LoginPageEnabled() bool

LoginPageEnabled 返回是否启用了登录页

func (*FormAuthenticator) Middleware

func (a *FormAuthenticator) Middleware() gin.HandlerFunc

Middleware 返回表单认证中间件

func (*FormAuthenticator) SetupRoutes

func (a *FormAuthenticator) SetupRoutes(router *gin.Engine)

SetupRoutes 设置表单认证的路由

type LoginPageData

type LoginPageData struct {
	Lang             string
	Title            string
	Header           string
	Subheader        string
	UsernameLabel    string
	PasswordLabel    string
	ButtonText       string
	Footer           string
	ErrorEmptyFields string
	ErrorCredentials string
}

LoginPageData 登录页面的数据结构

type NoAuthenticator

type NoAuthenticator struct{}

NoAuthenticator 实现了一个不进行认证的认证器

func NewNoAuth

func NewNoAuth() *NoAuthenticator

NewNoAuth 创建一个不进行认证的认证器

func (*NoAuthenticator) AuthType

func (a *NoAuthenticator) AuthType() AuthType

AuthType 返回认证类型

func (*NoAuthenticator) GetCredentials

func (a *NoAuthenticator) GetCredentials() (username, password string)

GetCredentials 返回认证凭据

func (*NoAuthenticator) LoginPageEnabled

func (a *NoAuthenticator) LoginPageEnabled() bool

LoginPageEnabled 返回是否启用了登录页

func (*NoAuthenticator) Middleware

func (a *NoAuthenticator) Middleware() gin.HandlerFunc

Middleware 返回一个不进行认证的中间件

type TokenAuthenticator

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

TokenAuthenticator 实现了基于令牌的认证

func NewTokenAuth

func NewTokenAuth(config Config) *TokenAuthenticator

NewTokenAuth 创建一个TokenAuth认证器

func (*TokenAuthenticator) AuthType

func (a *TokenAuthenticator) AuthType() AuthType

AuthType 返回认证类型

func (*TokenAuthenticator) GetCredentials

func (a *TokenAuthenticator) GetCredentials() (username, password string)

GetCredentials 返回认证凭据

func (*TokenAuthenticator) LoginPageEnabled

func (a *TokenAuthenticator) LoginPageEnabled() bool

LoginPageEnabled 返回是否启用了登录页

func (*TokenAuthenticator) Middleware

func (a *TokenAuthenticator) Middleware() gin.HandlerFunc

Middleware 返回一个检查令牌的中间件

Jump to

Keyboard shortcuts

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