@abapify/adt-auth

中文文档
0.4.34发布于 2026/11/03MITTypeScriptES Module构建来源已验证近 30 天下载 2826

SAP ADT 系统认证软件包 - 支持多种认证方法

中文使用文档
文档目录22 节
  1. 特征
  2. 安装
  3. 使用量
  4. 基本认证
  5. SAP 安全登录客户端( SLC)
  6. 多个系统
  7. API 密码
  8. 认证管理器
  9. 认证方法
  10. 存储
  11. 文件结构
  12. 会话格式
  13. 与客户合并
  14. 插件结构
  15. 插件合同
  16. 可用的插件
  17. 证书刷新
  18. 警卫
  19. 证书存储
  20. SLC 警卫
  21. 发展
  22. 许可证

@abapify/adt-auth (英语)

version

SAP ADT系统支持多种认证方法的认证软件包.

特征

  • ✅ 多重认证方法: Basic、SLC、OAuth(可扩展)
  • ✅ 安全存储: 基于文件并有适当的权限
  • ✅ 类型安全: 完整类型脚本支持
  • ✅ 可测试:容易嘲笑和测试
  • ✅ 可重复使用: 可用于任何节点.js工具

安装

npm install @abapify/adt-auth
# or
bun add @abapify/adt-auth

使用量

基本认证

import { AuthManager, BasicAuthMethod } from '@abapify/adt-auth';

const authManager = new AuthManager();
authManager.registerMethod(new BasicAuthMethod());

// Login
const session = await authManager.login(
  {
    method: 'basic',
    baseUrl: 'https://sap.example.com',
    username: 'user',
    password: 'pass',
    client: '100',
  },
  'TRL',
);

console.log('✅ Logged in!', session.sid);

// Later: get credentials
const credentials = authManager.getCredentials('TRL');

SAP 安全登录客户端( SLC)

import { AuthManager, SlcAuthMethod } from '@abapify/adt-auth';

const authManager = new AuthManager();
authManager.registerMethod(new SlcAuthMethod());

// Login (SLC handles authentication via proxy)
const session = await authManager.login(
  {
    method: 'slc',
    baseUrl: 'https://sap.example.com',
    slcProxy: {
      host: 'localhost',
      port: 3128,
    },
    client: '200',
  },
  'TRL',
);

console.log('✅ Logged in via SLC!');

多个系统

// Login to multiple systems
await authManager.login(config1, 'TRL');
await authManager.login(config2, 'QAS');
await authManager.login(config3, 'PRD');

// List all systems
const sids = authManager.listSids();
console.log('Available systems:', sids);

// Set default
authManager.setDefaultSid('TRL');

// Get default system credentials
const creds = authManager.getCredentials(); // Uses default SID

API 密码

认证管理器

主管弦乐以认证.

方法

  • registerMethod(method: AuthMethod) - 登记认证方法
  • login(config: AuthConfig, sid: string) - 登录和创建会话
  • getSession(sid?: string) - 获取会话( 如果未提供 sid 则默认使用)
  • getCredentials(sid?: string) - 获得会议资格
  • testSession(sid: string) - 测试会话是否仍然有效
  • logout(sid: string) - 删除会话
  • listSids() - 列出所有可用的SID
  • setDefaultSid(sid: string) - 设定默认 SID
  • getDefaultSid() - 获取默认 SID

认证方法

基本认证方法

用户名/ 密码认证 .

配置 :

{
  method: 'basic',
  baseUrl: string,
  username: string,
  password: string,
  client?: string,
  language?: string,
  insecure?: boolean,
}

SlCAuth 方法

SAP 安全登录客户端网络适配器.

配置 :

{
  method: 'slc',
  baseUrl: string,
  slcProxy: {
    host: string,
    port: number,
  },
  client?: string,
  language?: string,
}

先决条件:

  • SAP 安全登录客户端已安装并运行
  • 配置并激活 Web 适配器配置

存储

会话存储于 ~/.adt/sessions/ 有文件权限 0600 (所有者只读/写).

文件结构

~/.adt/
└── sessions/
    ├── TRL.json
    ├── QAS.json
    └── PRD.json

会话格式

{
  "sid": "TRL",
  "credentials": {
    "method": "basic",
    "baseUrl": "https://sap.example.com",
    "username": "user",
    "password": "encrypted",
    "client": "100"
  },
  "createdAt": "2025-01-01T00:00:00.000Z",
  "lastUsed": "2025-01-01T00:00:00.000Z"
}

与客户合并

import { createAdtClient } from '@abapify/adt-client';
import { AuthManager, BasicAuthMethod } from '@abapify/adt-auth';

// Get credentials
const authManager = new AuthManager();
authManager.registerMethod(new BasicAuthMethod());
const credentials = authManager.getCredentials('TRL');

if (!credentials) {
  throw new Error('Not authenticated. Run: adt login');
}

// Create ADT client
const client = createAdtClient({
  baseUrl: credentials.baseUrl,
  client: credentials.client,

  // Method-specific config
  ...(credentials.method === 'basic' && {
    username: credentials.username,
    password: credentials.password,
  }),

  ...(credentials.method === 'slc' && {
    proxy: credentials.slcProxy,
  }),
});

// Use client
const info =
  await client.adt.core.http.systeminformation.getSystemInformation();
console.log('System:', info);

插件结构

Auth插件提供认证方法. AuthManager 通用并代表插件.

插件合同

所有认证插件 MUST :

  1. 导出默认值 - 插件必须是默认导出
  2. 执行 AuthPlugin 接口 - 一定是这样 authenticate(options): Promise<AuthPluginResult>
  3. 返回 AuthPlugin 结果 - 标准格式
// Plugin implementation
import type {
  AuthPlugin,
  AuthPluginResult,
  AuthPluginOptions,
} from '@abapify/adt-auth';

const authPlugin: AuthPlugin = {
  async authenticate(options: AuthPluginOptions): Promise<AuthPluginResult> {
    // Your auth logic...
    return {
      method: 'cookie',
      credentials: {
        cookies: 'cookie-string',
        expiresAt: new Date(Date.now() + 8 * 60 * 60 * 1000),
      },
    };
  },
};

export default authPlugin;

可用的插件

  • @abapify/adt-puppeteer (英语) - 基于浏览器的SSO认证

证书刷新

当会话到期后, AuthManager 使用所存储的插件自动刷新 :

// AuthManager loads plugin dynamically
const pluginModule = await import(session.auth.plugin);
const result = await pluginModule.default.authenticate(options);

警卫

证书存储

  • 文件权限数字 : 0600 (所有者只读/写)
  • 目录权限数字 : 0700 (仅拥有者)
  • 密码加密: TODO( 目前为纯文本)

SLC 警卫

  • 没有存储证书( SLC 处理认证)
  • 只有代理配置已存储
  • 通过 SLC 基于证书的认证

发展

# Install dependencies
bun install

# Build
bun run build

# Test
bun test

# Type check
bun run typecheck

许可证

麻省理工学院

版本与发布记录

@abapify/adt-auth 共发布 30 个版本,首次发布于 2026/04/21;过去 12 个月发布了 30 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.34latest2026/11/034 天前
0.4.332026/11/025 天前
0.4.322026/11/025 天前
0.4.302026/10/317 天前
0.4.292026/10/308 天前
0.4.272026/10/308 天前

关于 @abapify/adt-auth 的常见问题

@abapify/adt-auth 是什么?

SAP ADT 系统认证软件包 - 支持多种认证方法

如何安装 @abapify/adt-auth?

在项目目录运行 npm install @abapify/adt-auth,或使用 pnpm add / yarn add / bun add。

@abapify/adt-auth 支持 TypeScript 吗?

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

@abapify/adt-auth 支持 ESM 还是 CommonJS?

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

@abapify/adt-auth 可以商用吗?

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

@abapify/adt-auth 的下载量有多少?

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

@abapify/adt-auth 还在维护吗?

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