Documentation
¶
Index ¶
- type Authenticator
- type Handler
- type Middleware
- func (m Middleware) RequireAnyRole(roles ...string) func(http.Handler) http.Handler
- func (m Middleware) RequireAuth() func(http.Handler) http.Handler
- func (m Middleware) RequireRole(role string) func(http.Handler) http.Handler
- func (m Middleware) RequireRoleAndScope(role, scope string) func(http.Handler) http.Handler
- func (m Middleware) RequireScope(scope string) func(http.Handler) http.Handler
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface {
AuthenticateBearer(ctx context.Context, token string) (authcore.Principal, bool, error)
}
Authenticator authenticates bearer tokens. Authenticator 校验 bearer token。
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves JSON bearer RBAC auth endpoints. Handler 提供 JSON bearer RBAC 认证端点。
func NewHandler ¶
NewHandler returns a Handler. NewHandler 返回 Handler。
func (*Handler) Middleware ¶
func (h *Handler) Middleware() Middleware
Middleware returns route middleware helpers for this Handler. Middleware 返回该 Handler 的路由 middleware 辅助工具。
type Middleware ¶
type Middleware struct {
Auth Authenticator
Roles corerbac.RolePolicy
}
Middleware builds RBAC route middleware. Middleware 构造 RBAC 路由中间件。
func NewMiddleware ¶
func NewMiddleware(auth Authenticator, roles corerbac.RolePolicy) Middleware
NewMiddleware returns RBAC middleware helpers. NewMiddleware 返回 RBAC middleware 辅助工具。
func (Middleware) RequireAnyRole ¶
RequireAnyRole requires at least one allowed role. RequireAnyRole 要求至少一个被允许的角色。
func (Middleware) RequireAuth ¶
func (m Middleware) RequireAuth() func(http.Handler) http.Handler
RequireAuth requires any authenticated principal. RequireAuth 要求任意已认证主体。
func (Middleware) RequireRole ¶
RequireRole requires a role allowed by the configured RolePolicy. RequireRole 要求配置的 RolePolicy 允许该角色。
func (Middleware) RequireRoleAndScope ¶
RequireRoleAndScope requires both a role and a scope. RequireRoleAndScope 同时要求角色与 scope。
func (Middleware) RequireScope ¶
RequireScope requires a scope. RequireScope 要求指定 scope。
type Options ¶
type Options struct {
// BasePath is a route prefix. Nil defaults to "/auth"; new("") selects the root.
// BasePath 是路由前缀;nil 默认使用 "/auth",new("") 选择根目录。
BasePath *string
MaxBodyBytes int64
TrustedProxies []netip.Prefix
RolePolicy corerbac.RolePolicy
}
Options configures NewHandler. Options 配置 NewHandler。
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns default handler options. DefaultOptions 返回默认 handler 选项。