@benlampson/heimdall-server

中文文档
5.10.0发布于 2026/11/07MITTypeScriptES Module近 30 天下载 2089

海姆达尔服务器OAuth,租户用户提供,只读目录和MCP认证适配器.

中文使用文档

@benlampson/heimdall-server

独立的 HeimdallUserProvisioningClient 通过标准 client_credentials 和显式授予的 heimdall.users.create 创建本租户普通用户,按当前应用 RBAC 授予普通默认角色。接口、角色配置和迁移见 用户创建接入。该能力从 5.6.0 起提供,浏览器包不增加接口,现有登录不变。

自 5.9.0 起,创建请求的可选 phone 是登录手机号;contactPhone 是可与其他账号共用的联系手机号。响应的 loginPhone 明确表示登录手机号,兼容字段 phone 保留;重复登录标识返回 409,错误的 conflictField 可帮助识别 username、email、phone 或通用 identifier 冲突。

Node 22+ 的 Heimdall 协议与只读目录客户端,版本跟随 Heimdall 整体 Release。支持 public/confidential 授权码、Device Code、服务 Token、刷新、JWT 校验、opaque Token、UserInfo、撤销/内省、退出地址和 MCP 认证头。没有 HTTP 路由、Cookie、UI 或数据库。

机密凭据由调用方的 credentialProvider 提供,不能将此入口打包到浏览器。完整示例与接口见仓库 sdk/README.md 和 sdk/API.md。

JWT 时间容差 clockSkewSeconds 默认 30,客户可设为非负安全整数秒数,0 禁用容差。nbf、exp、未来 iat 使用相同设置;缓存/刷新仍按真实到期时间执行,不跳过验签或身份边界。

import { HeimdallServerClient, HeimdallDirectoryClient } from '@benlampson/heimdall-server';
const server = new HeimdallServerClient({
  authority: 'https://idp.example.com/tenant-a', clientId: 'directory-service',
  audience: 'heimdall-directory-api', scope: 'heimdall.directory.read',
  tenantId: 'tenant-a', applicationId: 'business-app', authenticationMethod: 'client_secret_basic',
  credentialProvider: async () => ({ clientId: 'directory-service', secret: readSecret(), version: readSecretVersion() }),
});
const tokens = await server.getClientCredentialsToken();
const directory = new HeimdallDirectoryClient(server, 'https://api.example.com', 'tenant-a');
// const permissions = await directory.getUserPermissions(userId);

服务 Token 可选纯内存缓存,cacheClientCredentials:false 关闭;用户 Token 与登录事务由调用方保存。AK/SK 只提供 Heimdall /mcp 的专用认证头,不转换为 JWT。

版本与发布记录

@benlampson/heimdall-server 共发布 13 个版本,首次发布于 2026/10/11;过去 12 个月发布了 13 个版本。

版本发布日期距今
5.10.0latest2026/11/071 天前
5.9.42026/11/052 天前
5.9.32026/11/052 天前
5.9.22026/11/052 天前
5.9.12026/11/053 天前
5.9.02026/11/053 天前

关于 @benlampson/heimdall-server 的常见问题

@benlampson/heimdall-server 是什么?

海姆达尔服务器OAuth,租户用户提供,只读目录和MCP认证适配器.

如何安装 @benlampson/heimdall-server?

在项目目录运行 npm install @benlampson/heimdall-server,或使用 pnpm add / yarn add / bun add。

@benlampson/heimdall-server 支持 TypeScript 吗?

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

@benlampson/heimdall-server 支持 ESM 还是 CommonJS?

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

@benlampson/heimdall-server 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@benlampson/heimdall-server 可以商用吗?

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

@benlampson/heimdall-server 的下载量有多少?

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

@benlampson/heimdall-server 还在维护吗?

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