@abapify/adt-auth

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

Authentication package for SAP ADT systems - supports multiple auth methods

原始使用文档
文档目录22 节
  1. Features
  2. Installation
  3. Usage
  4. Basic Authentication
  5. SAP Secure Login Client (SLC)
  6. Multiple Systems
  7. API
  8. AuthManager
  9. Auth Methods
  10. Storage
  11. File Structure
  12. Session Format
  13. Integration with adt-client
  14. Plugin Architecture
  15. Plugin Contract
  16. Available Plugins
  17. Credential Refresh
  18. Security
  19. Credential Storage
  20. SLC Security
  21. Development
  22. License

@abapify/adt-auth

version

Authentication package for SAP ADT systems supporting multiple authentication methods.

Features

  • ✅ Multiple Auth Methods: Basic, SLC, OAuth (extensible)
  • ✅ Secure Storage: File-based with proper permissions
  • ✅ Type-Safe: Full TypeScript support
  • ✅ Testable: Easy to mock and test
  • ✅ Reusable: Can be used by any Node.js tool

Installation

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

Usage

Basic Authentication

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 Secure Login Client (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!');

Multiple Systems

// 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

AuthManager

Main orchestrator for authentication.

Methods

  • registerMethod(method: AuthMethod) - Register an auth method
  • login(config: AuthConfig, sid: string) - Login and create session
  • getSession(sid?: string) - Get session (uses default if sid not provided)
  • getCredentials(sid?: string) - Get credentials for a session
  • testSession(sid: string) - Test if session is still valid
  • logout(sid: string) - Delete session
  • listSids() - List all available SIDs
  • setDefaultSid(sid: string) - Set default SID
  • getDefaultSid() - Get default SID

Auth Methods

BasicAuthMethod

Username/password authentication.

Config:

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

SlcAuthMethod

SAP Secure Login Client Web Adapter.

Config:

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

Prerequisites:

  • SAP Secure Login Client installed and running
  • Web Adapter profile configured and active

Storage

Sessions are stored in ~/.adt/sessions/ with file permissions 0600 (owner read/write only).

File Structure

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

Session Format

{
  "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"
}

Integration with adt-client

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);

Plugin Architecture

Auth plugins provide authentication methods. AuthManager is generic and delegates to plugins.

Plugin Contract

All auth plugins MUST:

  1. Export default - The plugin must be the default export
  2. Implement AuthPlugin interface - Must have authenticate(options): Promise<AuthPluginResult>
  3. Return AuthPluginResult - Standard format
// 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;

Available Plugins

  • @abapify/adt-puppeteer - Browser-based SSO authentication

Credential Refresh

When sessions expire, AuthManager automatically refreshes using the stored plugin:

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

Security

Credential Storage

  • File permissions: 0600 (owner read/write only)
  • Directory permissions: 0700 (owner only)
  • Password encryption: TODO (currently plain text)

SLC Security

  • No credentials stored (SLC handles authentication)
  • Only proxy configuration stored
  • Certificate-based authentication via SLC

Development

# Install dependencies
bun install

# Build
bun run build

# Test
bun test

# Type check
bun run typecheck

License

MIT

版本与发布记录

@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 是什么?

Authentication package for SAP ADT systems - supports multiple auth methods

如何安装 @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 和提交记录判断。