@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。