authn

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package authn 是访问令牌的验签机制件:解析 Bearer 访问令牌与 X-Step-Up step-up 证明,验签后注入 appkit.Actor。判定(Require/Check)在框架根包, 本包只负责「凭证 → Actor」这一段——验签只写一次,模块经 ctx 只读。

claims 布局是框架与鉴权提供方之间的契约(提供方按此签发,换提供方即换 一个按此布局签发的实现,模块与框架零改动):

访问令牌(Bearer):iss(经 WithIssuer 校验)、sub=用户、exp 必填、
                   tid=业务租户(可选)、perms=精确权限码快照。
step-up(X-Step-Up):iss、sub(须与访问令牌一致)、exp 必填、
                   purpose="step-up"、iat=新鲜度判定依据。

提供方验「挑战动作」(MFA/TOTP 等)并签发 step-up 令牌;本包验「挑战 证明」(签名、iss、sub 一致、purpose、exp)。

挂载是组合根的部署面决策,通常一行:

appkit.Middleware(authn.Middleware(pub, "rbac-demo"))

issuer 此处为静态字符串;多分区部署(iss 随分区变化)需要按请求解析 issuer 的动态变体时再加,纯加法。

Index

Constants

View Source
const HeaderStepUp = "X-Step-Up"

HeaderStepUp 携带 step-up 证明(另一枚 JWT)。凭证不跨边界传播——每个 服务用自己的 Authn 重新验证——因此不进 callctx 白名单。

Variables

This section is empty.

Functions

func Middleware

func Middleware(pub ed25519.PublicKey, issuer string) func(http.Handler) http.Handler

Middleware 验签并注入 appkit.Actor。语义:

  • 无 Authorization 头的请求原样放行(不注入 Actor)——判公开与否是 Require 的职责,公开端点(探针等)不因本中间件存在而关死;
  • 有头但验签失败(坏签名、错算法、错 iss、过期、缺 exp、sub 为空) → 401:凭证无效必须响亮,不能静默降级为匿名;
  • X-Step-Up 同样原则:有头才验,验不过 401(含 sub 与访问令牌不一致、 purpose 不是 step-up);验过则 Actor.StepUpAt = 证明的 iat。

租户身份在此焊进 callctx:认证请求以令牌 tid 为准(覆盖或清零入站 X-Tenant-Id 头带来的值——该头只在内部东西向可信,外部入口可伪造)。 域代码与存储层(RLS)统一从 callctx.From(ctx).TenantID 取租户。

Types

This section is empty.

Jump to

Keyboard shortcuts

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