Documentation
¶
Index ¶
- func IsJWT(token string) bool
- func ParseAuthHeader(authHeader string) (scheme, token string)
- type AuthResult
- func TryAPIKeyAuth(authHeader string, store *AuthStore) *AuthResult
- func TryAPIKeyHeader(headerValue string, store *AuthStore) *AuthResult
- func TryBasic(authHeader string, store *AuthStore) *AuthResult
- func TryBearer(authHeader string, store *AuthStore) *AuthResult
- func TryJWT(tokenString string, jwtCfg *config.JWTConfig) *AuthResult
- type AuthStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseAuthHeader ¶
ParseAuthHeader 解析 Authorization header,返回 scheme 与 token
Types ¶
type AuthResult ¶
type AuthResult struct {
Method string // 认证方法: "basic", "bearer", "apikey", "jwt", "anonymous"
Name string // 配置名称(如 "admin-user")
User string // 用户名或 subject
Roles []string // 关联的角色
Metadata map[string]string // 额外的元数据(如 JWT issuer)
}
AuthResult 认证结果
func TryAPIKeyAuth ¶
func TryAPIKeyAuth(authHeader string, store *AuthStore) *AuthResult
TryAPIKeyAuth 尝试 API Key 认证(通过 Authorization: ApiKey xxx)
func TryAPIKeyHeader ¶
func TryAPIKeyHeader(headerValue string, store *AuthStore) *AuthResult
TryAPIKeyHeader 尝试 API Key 认证(通过 X-Api-Key header)
func TryBasic ¶
func TryBasic(authHeader string, store *AuthStore) *AuthResult
TryBasic 尝试 Basic Auth 认证
func TryBearer ¶
func TryBearer(authHeader string, store *AuthStore) *AuthResult
TryBearer 尝试 Bearer Token 认证
type AuthStore ¶
type AuthStore struct {
// 按凭证查找(用于认证)
BasicByUser map[string]config.BasicAuthConfig
BearerByToken map[string]config.BearerConfig
APIKeyByKey map[string]config.APIKeyConfig
// 按名称查找(用于策略验证)
BasicByName map[string]config.BasicAuthConfig
BearerByName map[string]config.BearerConfig
APIKeyByName map[string]config.APIKeyConfig
}
AuthStore 认证存储,用于快速查找
Click to show internal directories.
Click to hide internal directories.