auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LocalUser  = "user"
	LocalToken = "token"
)

Locals keys / locals key

Variables

View Source
var NoAuth bool

NoAuth disables all auth checks when enabled (dangerous). NoAuth 在启用时会关闭所有鉴权(危险模式)。

Functions

func AuthMiddleware

func AuthMiddleware(db *gorm.DB, jwtSecret string) fiber.Handler

AuthMiddleware verifies JWT and session status. AuthMiddleware 验证 JWT 与会话状态。

func RequireRoot

func RequireRoot() fiber.Handler

RequireRoot checks root privilege. RequireRoot 检查 root 权限。

func Sign

func Sign(secret, issuer, jti string, userID uint, username string, isRoot bool, tokenType string, expiresAt *time.Time) (string, error)

Sign signs a JWT with HS256. Sign 使用 HS256 签发 JWT。

Types

type ContextUser

type ContextUser struct {
	ID       uint
	Username string
	IsRoot   bool
}

ContextUser is stored in Fiber locals. ContextUser 存在于 Fiber locals 中。

type TokenClaims

type TokenClaims struct {
	jwt.RegisteredClaims

	// Username is duplicated for convenience.
	// Username 为方便起见冗余保存。
	Username string `json:"username"`

	// IsRoot indicates super user.
	// IsRoot 表示是否为超级用户。
	IsRoot bool `json:"is_root"`

	// TokenType: "web" or "api".
	// TokenType:token 类型,"web" 或 "api"。
	TokenType string `json:"typ"`
}

TokenClaims defines JWT claims used by gridbeat. TokenClaims 定义 gridbeat 使用的 JWT Claims。

func Parse

func Parse(secret string, tokenString string) (*TokenClaims, error)

Parse verifies and parses JWT. Parse 验证并解析 JWT。

Jump to

Keyboard shortcuts

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