@aauth/protocol

中文文档
2.0.0发布于 2026/09/09MITTypeScriptES Module近 30 天下载 1781

AAuth wire format — AAuth-Requirement and AAuth-Capabilities headers, access_mode planning, protocol constants

原始使用文档
文档目录7 节
  1. AAuth-Requirement
  2. AAuth-Capabilities
  3. access_mode
  4. Constants
  5. JWT decoding
  6. Not here
  7. License

@aauth/protocol

The AAuth wire format, on its own. Header build/parse, access_mode planning, protocol constants, and unverified JWT decoding. No I/O, no crypto.

Tracks draft-hardt-oauth-aauth-protocol-11.

One runtime dependency: @hellocoop/httpsig, imported for its RFC 8941 structured field parser (@hellocoop/httpsig/structured-fields). AAuth-Requirement is a Dictionary and AAuth-Capabilities is a List of Tokens, and every consumer of this package signs its requests with @hellocoop/httpsig anyway — so the parser is already installed, and a second implementation of the same grammar is a second place for the quoting and escaping rules to be got wrong.

npm install @aauth/protocol

AAuth-Requirement

import { parseRequirementHeader, buildRequirementHeader, UnsupportedRequirementError }
  from '@aauth/protocol'

// resource side
res.setHeader('AAuth-Requirement', buildRequirementHeader({
  requirement: 'auth-token',
  resourceToken,
}))

// agent side
try {
  const challenge = parseRequirementHeader(res.headers.get('AAuth-Requirement')!)
} catch (e) {
  if (e instanceof UnsupportedRequirementError) {
    // MUST NOT treat the response as satisfiable. Surface e.value to the caller.
  }
}

Recognized values: agent-token, person-token, auth-token, approval, interaction, clarification, claims. Anything else throws UnsupportedRequirementError, carrying the raw value. For a 202 the caller MAY keep polling Location in case a later response carries a value it knows.

requirement=auth-token requires a resource-token parameter and requirement=interaction requires code; a header missing one is malformed and throws a plain Error. url on requirement=interaction is optional: when it is absent the recipient composes {interaction_endpoint}?code=… from the issuer's published metadata. Unknown parameters are ignored.

AAuth-Capabilities

buildCapabilitiesHeader(['interaction', 'clarification'])  // "interaction, clarification"
parseCapabilitiesHeader('interaction, quantum-consent')    // ["interaction"]

Parsing filters unrecognized values and never throws — recipients MUST ignore what they do not recognize. Building does not filter: an agent unions its own capabilities with the ones its PS reports, which may be newer than this library.

An absent header is not an empty one. When the header is absent, recipients MUST NOT assume any capabilities.

access_mode

access_mode in /.well-known/aauth-resource.json is advisory — the runtime AAuth-Requirement is authoritative. planAccessMode gives an agent one of three answers and never throws.

const plan = planAccessMode(metadata.access_mode, { hasPersonServer: false })

switch (plan.kind) {
  case 'undeclared':     // absent or unrecognized — call the resource anyway
  case 'satisfiable':    // plan.mode is reachable with this setup
  case 'unsatisfiable':  // skip the resource, show plan.reason
}

Unrecognized values are undeclared, not errors: the value space is the AAuth Access Mode Value Registry, and an agent that stops on an unknown value breaks every time a value is registered.

unsatisfiable comes from an agent token with no ps claim. Three of the five modes reach a person server, and without one none of them can complete:

ModeNo person serverWhy
agent-tokensatisfiableIdentity only; no PS in the flow.
session-tokensatisfiableResource-managed; the resource issues its own credential.
person-tokenunsatisfiableThe agent must sign with a person token, which only a PS issues.
auth-tokenunsatisfiableThe resource token is exchanged for an auth token at the PS.
per-callunsatisfiableTerminates in an auth token — the grant is the r3_per_call claim.

Constants

TOKEN_TYP (the four typ values), DWK (the four well-known key documents), SIGNING_ALG — Ed25519, fully specified per RFC 9864. The polymorphic EdDSA MUST NOT be used.

JWT decoding

decodeJwtHeader and decodeJwtPayload parse a token's segments and throw on anything malformed. No signature verification. They prove nothing; never make a trust decision on their output.

Not here

AAuth-Mission was removed in -11, along with its IANA registration. A mission reaches a resource only inside a PS-issued token, as the mission_s256 claim. There are no mission header helpers in this package and there will not be.

License

MIT

版本与发布记录

@aauth/protocol 共发布 3 个版本,首次发布于 2026/08/13;过去 12 个月发布了 3 个版本。

版本发布日期距今
2.0.0latest2026/09/091 个月前
1.0.12026/08/142 个月前
1.0.02026/08/132 个月前

关于 @aauth/protocol 的常见问题

@aauth/protocol 是什么?

AAuth wire format — AAuth-Requirement and AAuth-Capabilities headers, access_mode planning, protocol constants

如何安装 @aauth/protocol?

在项目目录运行 npm install @aauth/protocol,或使用 pnpm add / yarn add / bun add。

@aauth/protocol 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aauth/protocol 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aauth/protocol 可以商用吗?

@aauth/protocol 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aauth/protocol 的下载量有多少?

根据 npm 官方下载统计,@aauth/protocol 在 2026/10/05 – 2026/11/03 这 30 天内被下载 1,781 次,日均约 59 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aauth/protocol 还在维护吗?

最新版本 2.0.0 发布于 2026/09/09(1 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/08/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。