@abapify/adt-auth 0.0.0 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +305 -1
  2. package/package.json +44 -3
package/README.md CHANGED
@@ -1,3 +1,307 @@
1
1
  # @abapify/adt-auth
2
2
 
3
- Placeholder. The real release is published via CI/CD.
3
+ [![version](https://img.shields.io/github/package-json/v/abapify/adt-cli?filename=packages/adt-auth/package.json)](https://github.com/abapify/adt-cli/pkgs/npm/%40abapify%2Fadt-auth)
4
+
5
+ Authentication package for SAP ADT systems supporting multiple authentication methods.
6
+
7
+ ## Features
8
+
9
+ - ✅ **Multiple Auth Methods**: Basic, SLC, OAuth (extensible)
10
+ - ✅ **Secure Storage**: File-based with proper permissions
11
+ - ✅ **Type-Safe**: Full TypeScript support
12
+ - ✅ **Testable**: Easy to mock and test
13
+ - ✅ **Reusable**: Can be used by any Node.js tool
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @abapify/adt-auth
19
+ # or
20
+ bun add @abapify/adt-auth
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### Basic Authentication
26
+
27
+ ```typescript
28
+ import { AuthManager, BasicAuthMethod } from '@abapify/adt-auth';
29
+
30
+ const authManager = new AuthManager();
31
+ authManager.registerMethod(new BasicAuthMethod());
32
+
33
+ // Login
34
+ const session = await authManager.login(
35
+ {
36
+ method: 'basic',
37
+ baseUrl: 'https://sap.example.com',
38
+ username: 'user',
39
+ password: 'pass',
40
+ client: '100',
41
+ },
42
+ 'BHF',
43
+ );
44
+
45
+ console.log('✅ Logged in!', session.sid);
46
+
47
+ // Later: get credentials
48
+ const credentials = authManager.getCredentials('BHF');
49
+ ```
50
+
51
+ ### SAP Secure Login Client (SLC)
52
+
53
+ ```typescript
54
+ import { AuthManager, SlcAuthMethod } from '@abapify/adt-auth';
55
+
56
+ const authManager = new AuthManager();
57
+ authManager.registerMethod(new SlcAuthMethod());
58
+
59
+ // Login (SLC handles authentication via proxy)
60
+ const session = await authManager.login(
61
+ {
62
+ method: 'slc',
63
+ baseUrl: 'https://sap.example.com',
64
+ slcProxy: {
65
+ host: 'localhost',
66
+ port: 3128,
67
+ },
68
+ client: '200',
69
+ },
70
+ 'BHF',
71
+ );
72
+
73
+ console.log('✅ Logged in via SLC!');
74
+ ```
75
+
76
+ ### Multiple Systems
77
+
78
+ ```typescript
79
+ // Login to multiple systems
80
+ await authManager.login(config1, 'BHF');
81
+ await authManager.login(config2, 'S0D');
82
+ await authManager.login(config3, 'PRD');
83
+
84
+ // List all systems
85
+ const sids = authManager.listSids();
86
+ console.log('Available systems:', sids);
87
+
88
+ // Set default
89
+ authManager.setDefaultSid('BHF');
90
+
91
+ // Get default system credentials
92
+ const creds = authManager.getCredentials(); // Uses default SID
93
+ ```
94
+
95
+ ## API
96
+
97
+ ### AuthManager
98
+
99
+ Main orchestrator for authentication.
100
+
101
+ #### Methods
102
+
103
+ - `registerMethod(method: AuthMethod)` - Register an auth method
104
+ - `login(config: AuthConfig, sid: string)` - Login and create session
105
+ - `getSession(sid?: string)` - Get session (uses default if sid not provided)
106
+ - `getCredentials(sid?: string)` - Get credentials for a session
107
+ - `testSession(sid: string)` - Test if session is still valid
108
+ - `logout(sid: string)` - Delete session
109
+ - `listSids()` - List all available SIDs
110
+ - `setDefaultSid(sid: string)` - Set default SID
111
+ - `getDefaultSid()` - Get default SID
112
+
113
+ ### Auth Methods
114
+
115
+ #### BasicAuthMethod
116
+
117
+ Username/password authentication.
118
+
119
+ **Config:**
120
+
121
+ ```typescript
122
+ {
123
+ method: 'basic',
124
+ baseUrl: string,
125
+ username: string,
126
+ password: string,
127
+ client?: string,
128
+ language?: string,
129
+ insecure?: boolean,
130
+ }
131
+ ```
132
+
133
+ #### SlcAuthMethod
134
+
135
+ SAP Secure Login Client Web Adapter.
136
+
137
+ **Config:**
138
+
139
+ ```typescript
140
+ {
141
+ method: 'slc',
142
+ baseUrl: string,
143
+ slcProxy: {
144
+ host: string,
145
+ port: number,
146
+ },
147
+ client?: string,
148
+ language?: string,
149
+ }
150
+ ```
151
+
152
+ **Prerequisites:**
153
+
154
+ - SAP Secure Login Client installed and running
155
+ - Web Adapter profile configured and active
156
+
157
+ ## Storage
158
+
159
+ Sessions are stored in `~/.adt/sessions/` with file permissions `0600` (owner read/write only).
160
+
161
+ ### File Structure
162
+
163
+ ```
164
+ ~/.adt/
165
+ └── sessions/
166
+ ├── BHF.json
167
+ ├── S0D.json
168
+ └── PRD.json
169
+ ```
170
+
171
+ ### Session Format
172
+
173
+ ```json
174
+ {
175
+ "sid": "BHF",
176
+ "credentials": {
177
+ "method": "basic",
178
+ "baseUrl": "https://sap.example.com",
179
+ "username": "user",
180
+ "password": "encrypted",
181
+ "client": "100"
182
+ },
183
+ "createdAt": "2025-01-01T00:00:00.000Z",
184
+ "lastUsed": "2025-01-01T00:00:00.000Z"
185
+ }
186
+ ```
187
+
188
+ ## Integration with adt-client
189
+
190
+ ```typescript
191
+ import { createAdtClient } from '@abapify/adt-client';
192
+ import { AuthManager, BasicAuthMethod } from '@abapify/adt-auth';
193
+
194
+ // Get credentials
195
+ const authManager = new AuthManager();
196
+ authManager.registerMethod(new BasicAuthMethod());
197
+ const credentials = authManager.getCredentials('BHF');
198
+
199
+ if (!credentials) {
200
+ throw new Error('Not authenticated. Run: adt login');
201
+ }
202
+
203
+ // Create ADT client
204
+ const client = createAdtClient({
205
+ baseUrl: credentials.baseUrl,
206
+ client: credentials.client,
207
+
208
+ // Method-specific config
209
+ ...(credentials.method === 'basic' && {
210
+ username: credentials.username,
211
+ password: credentials.password,
212
+ }),
213
+
214
+ ...(credentials.method === 'slc' && {
215
+ proxy: credentials.slcProxy,
216
+ }),
217
+ });
218
+
219
+ // Use client
220
+ const info =
221
+ await client.adt.core.http.systeminformation.getSystemInformation();
222
+ console.log('System:', info);
223
+ ```
224
+
225
+ ## Plugin Architecture
226
+
227
+ Auth plugins provide authentication methods. AuthManager is generic and delegates to plugins.
228
+
229
+ ### Plugin Contract
230
+
231
+ All auth plugins MUST:
232
+
233
+ 1. **Export default** - The plugin must be the default export
234
+ 2. **Implement AuthPlugin interface** - Must have `authenticate(options): Promise<AuthPluginResult>`
235
+ 3. **Return AuthPluginResult** - Standard format
236
+
237
+ ```typescript
238
+ // Plugin implementation
239
+ import type {
240
+ AuthPlugin,
241
+ AuthPluginResult,
242
+ AuthPluginOptions,
243
+ } from '@abapify/adt-auth';
244
+
245
+ const authPlugin: AuthPlugin = {
246
+ async authenticate(options: AuthPluginOptions): Promise<AuthPluginResult> {
247
+ // Your auth logic...
248
+ return {
249
+ method: 'cookie',
250
+ credentials: {
251
+ cookies: 'cookie-string',
252
+ expiresAt: new Date(Date.now() + 8 * 60 * 60 * 1000),
253
+ },
254
+ };
255
+ },
256
+ };
257
+
258
+ export default authPlugin;
259
+ ```
260
+
261
+ ### Available Plugins
262
+
263
+ - **@abapify/adt-puppeteer** - Browser-based SSO authentication
264
+
265
+ ### Credential Refresh
266
+
267
+ When sessions expire, AuthManager automatically refreshes using the stored plugin:
268
+
269
+ ```typescript
270
+ // AuthManager loads plugin dynamically
271
+ const pluginModule = await import(session.auth.plugin);
272
+ const result = await pluginModule.default.authenticate(options);
273
+ ```
274
+
275
+ ## Security
276
+
277
+ ### Credential Storage
278
+
279
+ - **File permissions**: `0600` (owner read/write only)
280
+ - **Directory permissions**: `0700` (owner only)
281
+ - **Password encryption**: TODO (currently plain text)
282
+
283
+ ### SLC Security
284
+
285
+ - No credentials stored (SLC handles authentication)
286
+ - Only proxy configuration stored
287
+ - Certificate-based authentication via SLC
288
+
289
+ ## Development
290
+
291
+ ```bash
292
+ # Install dependencies
293
+ bun install
294
+
295
+ # Build
296
+ bun run build
297
+
298
+ # Test
299
+ bun test
300
+
301
+ # Type check
302
+ bun run typecheck
303
+ ```
304
+
305
+ ## License
306
+
307
+ MIT
package/package.json CHANGED
@@ -1,5 +1,46 @@
1
1
  {
2
2
  "name": "@abapify/adt-auth",
3
- "version": "0.0.0",
4
- "description": "Placeholder — real package is published via CI/CD (trusted publishing)."
5
- }
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "version": "0.3.6",
7
+ "description": "Authentication package for SAP ADT systems - supports multiple auth methods",
8
+ "type": "module",
9
+ "types": "./dist/index.d.mts",
10
+ "exports": {
11
+ ".": "./dist/index.mjs",
12
+ "./basic": "./dist/basic.mjs",
13
+ "./plugins/basic": "./dist/plugins/basic.mjs",
14
+ "./plugins/service-key": "./dist/plugins/service-key.mjs",
15
+ "./service-key": "./dist/service-key.mjs",
16
+ "./utils/env": "./dist/utils/env.mjs",
17
+ "./package.json": "./package.json"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md"
22
+ ],
23
+ "dependencies": {
24
+ "@abapify/logger": "0.3.6",
25
+ "proxy-agent": "^6.4.0"
26
+ },
27
+ "keywords": [
28
+ "sap",
29
+ "adt",
30
+ "authentication",
31
+ "abap",
32
+ "slc",
33
+ "oauth"
34
+ ],
35
+ "author": "Booking.com",
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/abapify/adt-cli.git",
40
+ "directory": "packages/adt-auth"
41
+ },
42
+ "homepage": "https://github.com/abapify/adt-cli/tree/main/packages/adt-auth#readme",
43
+ "bugs": {
44
+ "url": "https://github.com/abapify/adt-cli/issues"
45
+ }
46
+ }