@mcp-abap-adt/connection 9.4.2 → 10.0.2
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.
- package/CHANGELOG.md +182 -1
- package/README.md +78 -37
- package/dist/connection/AbstractAbapConnection.d.ts +211 -56
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
- package/dist/connection/AbstractAbapConnection.js +622 -255
- package/dist/connection/CloudHttpTransport.d.ts.map +1 -1
- package/dist/connection/CloudHttpTransport.js +15 -5
- package/dist/connection/CredentialAbapConnection.d.ts +21 -20
- package/dist/connection/CredentialAbapConnection.d.ts.map +1 -1
- package/dist/connection/CredentialAbapConnection.js +39 -46
- package/dist/connection/HttpTransport.d.ts +30 -14
- package/dist/connection/HttpTransport.d.ts.map +1 -1
- package/dist/connection/HttpTransport.js +99 -19
- package/dist/connection/IAdtTransport.d.ts +19 -2
- package/dist/connection/IAdtTransport.d.ts.map +1 -1
- package/dist/connection/OnPremHttpTransport.d.ts.map +1 -1
- package/dist/connection/OnPremHttpTransport.js +4 -3
- package/dist/connection/RfcTransport.d.ts +23 -3
- package/dist/connection/RfcTransport.d.ts.map +1 -1
- package/dist/connection/RfcTransport.js +48 -15
- package/dist/connection/authErrors.d.ts +61 -0
- package/dist/connection/authErrors.d.ts.map +1 -0
- package/dist/connection/authErrors.js +78 -0
- package/dist/connection/requestTarget.d.ts +12 -0
- package/dist/connection/requestTarget.d.ts.map +1 -0
- package/dist/connection/requestTarget.js +23 -0
- package/dist/connection/rfcConversation.d.ts +10 -5
- package/dist/connection/rfcConversation.d.ts.map +1 -1
- package/dist/connection/rfcConversation.js +6 -8
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -12
- package/dist/session/SessionLifecycle.d.ts +1 -1
- package/dist/session/SessionLifecycle.d.ts.map +1 -1
- package/docs/INDEX.md +4 -1
- package/docs/INSTALLATION.md +15 -7
- package/docs/JWT_AUTH_TOOLS.md +2 -2
- package/docs/MIGRATION-10.0.md +284 -0
- package/docs/SCOPE.md +2 -2
- package/docs/STATEFUL_SESSION_GUIDE.md +30 -10
- package/docs/USAGE.md +118 -35
- package/examples/README.md +5 -4
- package/examples/basic-connection.js +1 -1
- package/examples/jwt-with-token-refresh.js +14 -15
- package/examples/saml-connection.js +1 -1
- package/package.json +5 -4
- package/dist/auth/FileCertificateMaterialLoader.d.ts +0 -6
- package/dist/auth/FileCertificateMaterialLoader.d.ts.map +0 -1
- package/dist/auth/FileCertificateMaterialLoader.js +0 -28
- package/dist/auth/ntlm.d.ts +0 -26
- package/dist/auth/ntlm.d.ts.map +0 -1
- package/dist/auth/ntlm.js +0 -72
- package/dist/auth/providers.d.ts +0 -125
- package/dist/auth/providers.d.ts.map +0 -1
- package/dist/auth/providers.js +0 -183
- package/dist/utils/tokenRefresh.d.ts +0 -15
- package/dist/utils/tokenRefresh.d.ts.map +0 -1
- package/dist/utils/tokenRefresh.js +0 -55
package/docs/USAGE.md
CHANGED
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
```typescript
|
|
19
19
|
import {
|
|
20
20
|
AdtOnPremConnector,
|
|
21
|
-
BasicAuthProvider,
|
|
22
21
|
OnPremHttpTransport,
|
|
23
22
|
getTimeout,
|
|
24
23
|
} from '@mcp-abap-adt/connection';
|
|
24
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
25
25
|
import { SapConfig } from '@mcp-abap-adt/connection';
|
|
26
26
|
|
|
27
27
|
const config: SapConfig = {
|
|
@@ -90,9 +90,9 @@ For on-premise SAP systems using basic authentication:
|
|
|
90
90
|
```typescript
|
|
91
91
|
import {
|
|
92
92
|
AdtOnPremConnector,
|
|
93
|
-
BasicAuthProvider,
|
|
94
93
|
OnPremHttpTransport,
|
|
95
94
|
} from '@mcp-abap-adt/connection';
|
|
95
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
96
96
|
|
|
97
97
|
const config = {
|
|
98
98
|
url: 'https://sap-server.local:8000',
|
|
@@ -123,9 +123,9 @@ For SAP BTP ABAP Environment. Token refresh belongs to
|
|
|
123
123
|
import {
|
|
124
124
|
AdtCloudConnector,
|
|
125
125
|
CloudHttpTransport,
|
|
126
|
-
TokenAuthProvider,
|
|
127
126
|
getTimeout,
|
|
128
127
|
} from '@mcp-abap-adt/connection';
|
|
128
|
+
import { TokenAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
129
129
|
|
|
130
130
|
const config = {
|
|
131
131
|
url: 'https://tenant.abap.cloud',
|
|
@@ -133,12 +133,12 @@ const config = {
|
|
|
133
133
|
client: '100', // Optional for cloud
|
|
134
134
|
};
|
|
135
135
|
|
|
136
|
-
//
|
|
137
|
-
// ITokenRefresher
|
|
138
|
-
//
|
|
136
|
+
// `.fixed` is a token with no renewal behind it. `TokenAuthProvider.from` takes
|
|
137
|
+
// an ITokenRefresher — from @mcp-abap-adt/auth-broker or your own — and renews
|
|
138
|
+
// when the system refuses the token.
|
|
139
139
|
const connection = new AdtCloudConnector(
|
|
140
140
|
config,
|
|
141
|
-
|
|
141
|
+
TokenAuthProvider.fixed('eyJhbGciOiJSUzI1NiIs...'),
|
|
142
142
|
new CloudHttpTransport(() => ({}), logger, {
|
|
143
143
|
client: config.client,
|
|
144
144
|
baseUrl: config.url,
|
|
@@ -234,7 +234,8 @@ await connection.makeAdtRequest({
|
|
|
234
234
|
By default, connections are stateless - each request gets fresh cookies and CSRF tokens:
|
|
235
235
|
|
|
236
236
|
```typescript
|
|
237
|
-
import { AdtOnPremConnector,
|
|
237
|
+
import { AdtOnPremConnector, OnPremHttpTransport, getTimeout } from '@mcp-abap-adt/connection';
|
|
238
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
238
239
|
const connection = new AdtOnPremConnector(
|
|
239
240
|
config,
|
|
240
241
|
new BasicAuthProvider(config.username!, config.password!),
|
|
@@ -259,7 +260,8 @@ writes from running in the lock context and failing with PAK/058 or an invalid
|
|
|
259
260
|
lock handle. See [HTTP context isolation](./STATEFUL_SESSION_GUIDE.md#http-context-isolation-931).
|
|
260
261
|
|
|
261
262
|
```typescript
|
|
262
|
-
import { AdtOnPremConnector,
|
|
263
|
+
import { AdtOnPremConnector, OnPremHttpTransport, getTimeout } from '@mcp-abap-adt/connection';
|
|
264
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
263
265
|
const connection = new AdtOnPremConnector(
|
|
264
266
|
config,
|
|
265
267
|
new BasicAuthProvider(config.username!, config.password!),
|
|
@@ -375,7 +377,8 @@ implied. Four things follow from it.
|
|
|
375
377
|
### connect() is required, and it tells the truth
|
|
376
378
|
|
|
377
379
|
```typescript
|
|
378
|
-
import { AdtOnPremConnector,
|
|
380
|
+
import { AdtOnPremConnector, OnPremHttpTransport } from '@mcp-abap-adt/connection';
|
|
381
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
379
382
|
|
|
380
383
|
const connection = new AdtOnPremConnector(
|
|
381
384
|
config,
|
|
@@ -490,8 +493,7 @@ precisely to avoid it.
|
|
|
490
493
|
|
|
491
494
|
Two different things can cost you the session, and they do not behave alike.
|
|
492
495
|
|
|
493
|
-
**The session was replaced** — a
|
|
494
|
-
changed underneath you. This is fatal **only while a lock window is open**:
|
|
496
|
+
**The session was replaced** — a session cookie that changed underneath you. This is fatal **only while a lock window is open**:
|
|
495
497
|
|
|
496
498
|
```typescript
|
|
497
499
|
// window open → ADT_SESSION_REPLACED, the connection stops being usable
|
|
@@ -520,7 +522,8 @@ yours.
|
|
|
520
522
|
Session IDs are auto-generated (UUID) when connection is created:
|
|
521
523
|
|
|
522
524
|
```typescript
|
|
523
|
-
import { AdtOnPremConnector,
|
|
525
|
+
import { AdtOnPremConnector, OnPremHttpTransport } from '@mcp-abap-adt/connection';
|
|
526
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
524
527
|
const connection = new AdtOnPremConnector(
|
|
525
528
|
config,
|
|
526
529
|
new BasicAuthProvider(config.username!, config.password!),
|
|
@@ -550,7 +553,8 @@ console.log(connectionWithOwnId.getSessionId()); // 'custom-session-123'
|
|
|
550
553
|
Dynamically switch between stateful and stateless modes:
|
|
551
554
|
|
|
552
555
|
```typescript
|
|
553
|
-
import { AdtOnPremConnector,
|
|
556
|
+
import { AdtOnPremConnector, OnPremHttpTransport, getTimeout } from '@mcp-abap-adt/connection';
|
|
557
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
554
558
|
// Start in stateless mode (default)
|
|
555
559
|
const connection = new AdtOnPremConnector(
|
|
556
560
|
config,
|
|
@@ -592,7 +596,8 @@ in a `finally`. `disconnect()` never throws, so it is safe there.
|
|
|
592
596
|
### Using Custom Logger
|
|
593
597
|
|
|
594
598
|
```typescript
|
|
595
|
-
import { AdtOnPremConnector,
|
|
599
|
+
import { AdtOnPremConnector, ILogger, OnPremHttpTransport } from '@mcp-abap-adt/connection';
|
|
600
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
596
601
|
|
|
597
602
|
class CustomLogger implements ILogger {
|
|
598
603
|
info(message: string, meta?: any) {
|
|
@@ -791,7 +796,11 @@ establishing, and whatever session state it keeps.
|
|
|
791
796
|
|
|
792
797
|
```text
|
|
793
798
|
new HttpTransport(agentOptions?, logger?, { client?, baseUrl? })
|
|
794
|
-
new RfcTransport(
|
|
799
|
+
new RfcTransport(
|
|
800
|
+
connect: (logon: Readonly<Record<string, string>>) => IRfcConversation,
|
|
801
|
+
logger?,
|
|
802
|
+
{ logWire?, maxLoggedBodyChars? },
|
|
803
|
+
)
|
|
795
804
|
```
|
|
796
805
|
|
|
797
806
|
`HttpTransport` is the ordinary wire, and you name it because the connector
|
|
@@ -801,6 +810,21 @@ what the connectors' type parameters admit. `RfcTransport`
|
|
|
801
810
|
you build with `rfcConversationFrom(config)`, which derives `ashost` and `sysnr`
|
|
802
811
|
and loads the SAP NW RFC SDK only when a conversation opens.
|
|
803
812
|
|
|
813
|
+
**What the wire takes from the credential.** The provider writes it, the wire
|
|
814
|
+
carries it; the wire never reads `config.username` or `config.password`.
|
|
815
|
+
|
|
816
|
+
- HTTP takes TLS material (`cert`, `key`, `pfx`, `passphrase`) at logon and builds
|
|
817
|
+
its `https.Agent` from it. `agentOptions` stays for what is not the credential
|
|
818
|
+
— `ca` and `rejectUnauthorized`. A later logon offering different material
|
|
819
|
+
replaces the client; the cookie jar and CSRF token are the session's and stay.
|
|
820
|
+
HTTP refuses logon parameters.
|
|
821
|
+
- RFC takes logon parameters (a password, or SNC settings) on every conversation
|
|
822
|
+
it opens, the session's own and each per-call one. RFC refuses TLS material,
|
|
823
|
+
and a provider that writes no logon parameters (a bearer token) cannot log on
|
|
824
|
+
over RFC: the open fails, the provider is asked, and you get its refusal.
|
|
825
|
+
- A failed RFC open is thrown as `WireLogonError` with the SDK's own error as
|
|
826
|
+
`cause`, so a provider can read the SDK's `key` and message.
|
|
827
|
+
|
|
804
828
|
**`logWire` dumps the wire, and is off.** With it on, `RfcTransport` adds three
|
|
805
829
|
debug lines per request — the header fields, the request body and the response
|
|
806
830
|
body — which is what tells you a payload was mis-serialised before it reached
|
|
@@ -909,41 +933,100 @@ export class CloudSdkAbapConnection {
|
|
|
909
933
|
|
|
910
934
|
### The credential, and how a refusal is classified
|
|
911
935
|
|
|
912
|
-
For SAP BTP cloud systems, hand `AdtCloudConnector` a
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
job, not this package's.
|
|
936
|
+
For SAP BTP cloud systems, hand `AdtCloudConnector` a token provider from
|
|
937
|
+
`@mcp-abap-adt/auth-providers`: `TokenAuthProvider.fixed(token)` is a token with
|
|
938
|
+
nothing behind it, `TokenAuthProvider.from(refresher)` takes an `ITokenRefresher`
|
|
939
|
+
and renews a token the system refused. Obtaining tokens in the first place is
|
|
940
|
+
`@mcp-abap-adt/auth-broker`'s job, not this package's.
|
|
917
941
|
|
|
918
942
|
```text
|
|
919
943
|
new AdtCloudConnector(
|
|
920
944
|
config,
|
|
921
|
-
|
|
945
|
+
TokenAuthProvider.from(refresher), // or TokenAuthProvider.fixed(token)
|
|
922
946
|
new CloudHttpTransport(() => ({}), logger, { client: config.client, baseUrl: config.url }),
|
|
923
947
|
logger,
|
|
924
948
|
);
|
|
925
949
|
```
|
|
926
950
|
|
|
927
|
-
|
|
928
|
-
|
|
951
|
+
#### When the credential is refused
|
|
952
|
+
|
|
953
|
+
The connection speaks four calls to whatever `IAuthProvider` it holds, and
|
|
954
|
+
never asks what kind it is:
|
|
955
|
+
|
|
956
|
+
| call | when |
|
|
957
|
+
|---|---|
|
|
958
|
+
| `prepare()` | once, in `connect()`, before the wire opens |
|
|
959
|
+
| `establish(logon)` | at each logon the wire performs |
|
|
960
|
+
| `authorize(request)` | before every attempt of every request — including the CSRF fetch, the cloud preflight, the logoff, and each resend |
|
|
961
|
+
| `rejected(rejection)` | the system said no |
|
|
962
|
+
|
|
963
|
+
**Each request asks the provider.** Nothing is cached by the connection, so a
|
|
964
|
+
token the provider renewed is on the very next attempt.
|
|
965
|
+
|
|
966
|
+
**How failures are classified:**
|
|
929
967
|
|
|
930
968
|
| answer | what happens |
|
|
931
969
|
|---|---|
|
|
932
|
-
| **401**
|
|
933
|
-
| **
|
|
970
|
+
| **401** on a stale CSRF token or a login form | the wire's own session recovery runs first; a session fault is not a credential fault, and never reaches the provider. For a mutation refused while a CSRF token is cached, that recovery starts a new session — except inside a critical section, where the 401 goes straight to the provider (next row) so the session and its lock are kept |
|
|
971
|
+
| **401** that survives that recovery, or a logon the system refused | put to `provider.rejected({ at, status?, error })`. On Ok the request is authorized again and sent **once more**; on no, `AuthRefusedError` |
|
|
972
|
+
| the same refusal after an Ok | the verdict. The provider is not asked again — asking would invite a second renewal — and you get an `AuthRefusedError` saying the credential was refused again after the provider renewed it |
|
|
973
|
+
| **403** | propagates untouched, never put to the provider. The server authenticated the caller and refused the action anyway, so a new credential is the same caller — usually the body names the authorization object |
|
|
934
974
|
| anything else | untouched |
|
|
935
975
|
|
|
936
|
-
The
|
|
937
|
-
|
|
976
|
+
The one more attempt keeps the request's own lease and generation, so
|
|
977
|
+
stale-request fencing applies to it: a request from a superseded session asks
|
|
978
|
+
nobody and gets its error back. After a rejection `at: 'request'` it goes out on
|
|
979
|
+
the same session; after a rejection `at: 'logon'` the wire logs on again — token
|
|
980
|
+
dropped, established anew — before the resend. Inside a critical section a
|
|
981
|
+
renewal keeps the session: a mutation that meets a 401 with a CSRF token cached
|
|
982
|
+
is resent on it with the same token, and if SAP did replace the session the
|
|
983
|
+
request fails with `SESSION_REPLACED` rather than carrying on in a new one.
|
|
984
|
+
Outside a critical section that mutation takes the wire's stale-session recovery
|
|
985
|
+
first (above), which starts a new session.
|
|
986
|
+
|
|
987
|
+
**The price of keeping the lock.** Inside a critical section the connection
|
|
988
|
+
cannot tell a dead session from a refused credential when SAP answers the resend
|
|
989
|
+
with the same session cookie and no `Set-Cookie`: the 401 comes back a second
|
|
990
|
+
time, and the request ends as `AuthRefusedError` with the refused-again verdict
|
|
991
|
+
(`at: 'request'`), not `SESSION_REPLACED`. The connection stays connected on
|
|
992
|
+
that session. If you get this inside a critical section, treat the lock as lost:
|
|
993
|
+
`disconnect()`, `connect()`, and redo the work under a new lock. That is the
|
|
994
|
+
intended trade-off — a renewal must not discard a lock the session still holds.
|
|
995
|
+
|
|
996
|
+
One credential retry per request: the upfront token fetch before a mutation and
|
|
997
|
+
a later rejection draw on the same allowance.
|
|
938
998
|
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
999
|
+
```typescript
|
|
1000
|
+
import { AuthRefusedError } from '@mcp-abap-adt/connection';
|
|
1001
|
+
|
|
1002
|
+
try {
|
|
1003
|
+
await connection.connect();
|
|
1004
|
+
} catch (error) {
|
|
1005
|
+
if (error instanceof AuthRefusedError) {
|
|
1006
|
+
// error.refusal.reason / .hint are the provider's words;
|
|
1007
|
+
// error.at is 'prepare' | 'logon' | 'request'; error.cause is the provider's
|
|
1008
|
+
// throw when it threw, else the wire's error.
|
|
1009
|
+
console.error(error.message);
|
|
1010
|
+
}
|
|
1011
|
+
throw error;
|
|
1012
|
+
}
|
|
1013
|
+
```
|
|
942
1014
|
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1015
|
+
`refusal` is the provider's, `cause` is the error the wire raised as it arrived,
|
|
1016
|
+
so a network failure stays visible even when a provider words it as a credential
|
|
1017
|
+
problem. A provider that throws is treated as refusing with the reason "the
|
|
1018
|
+
credential provider failed" and the throw as the cause.
|
|
1019
|
+
|
|
1020
|
+
**Concurrency.** Many requests meeting the same expired token each call
|
|
1021
|
+
`rejected()`; the connection adds no single-flight of its own. They share one
|
|
1022
|
+
renewal in flight only if the provider shares one: `TokenAuthProvider.from` asks
|
|
1023
|
+
its refresher on each rejection, so they share one only if your refresher does.
|
|
1024
|
+
|
|
1025
|
+
**A refusal during `connect()`** is the same story: `prepare()` refused sends
|
|
1026
|
+
nothing; a logon the system refused goes to `rejected({ at: 'logon' })`, and on
|
|
1027
|
+
Ok the wire is closed and logged on once more. An `establish` refusal is the
|
|
1028
|
+
provider's own verdict on this logon (SNC with no library, a certificate the wire
|
|
1029
|
+
cannot take) and does not go to `rejected`.
|
|
947
1030
|
|
|
948
1031
|
### Configuration Types
|
|
949
1032
|
|
package/examples/README.md
CHANGED
|
@@ -8,6 +8,7 @@ This directory contains example code demonstrating how to use the `@mcp-abap-adt
|
|
|
8
8
|
# Install dependencies
|
|
9
9
|
cd packages/connection
|
|
10
10
|
npm install
|
|
11
|
+
npm install @mcp-abap-adt/auth-providers # the credential providers the examples use
|
|
11
12
|
|
|
12
13
|
# Build the package
|
|
13
14
|
npm run build
|
|
@@ -42,9 +43,9 @@ node examples/jwt-with-token-refresh.js
|
|
|
42
43
|
```
|
|
43
44
|
|
|
44
45
|
**What it demonstrates:**
|
|
45
|
-
- Creating connection with
|
|
46
|
-
-
|
|
47
|
-
-
|
|
46
|
+
- Creating connection with `TokenAuthProvider.from(refresher)` (from `@mcp-abap-adt/auth-providers`)
|
|
47
|
+
- A 401 put to the provider, which renews the token
|
|
48
|
+
- Exactly one more attempt with the renewed token
|
|
48
49
|
- A 403 propagating untouched, with its status and body intact
|
|
49
50
|
|
|
50
51
|
### saml-connection.js
|
|
@@ -56,7 +57,7 @@ node examples/saml-connection.js
|
|
|
56
57
|
```
|
|
57
58
|
|
|
58
59
|
**What it demonstrates:**
|
|
59
|
-
- Creating SAML connection
|
|
60
|
+
- Creating a SAML connection with `SamlAuthProvider` (from `@mcp-abap-adt/auth-providers`)
|
|
60
61
|
- Using `sessionCookies` from environment
|
|
61
62
|
- Fetching CSRF token and making ADT request with cookie auth
|
|
62
63
|
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
const {
|
|
8
8
|
OnPremHttpTransport,
|
|
9
9
|
AdtOnPremConnector,
|
|
10
|
-
BasicAuthProvider,
|
|
11
10
|
} = require('@mcp-abap-adt/connection');
|
|
11
|
+
const { BasicAuthProvider } = require('@mcp-abap-adt/auth-providers');
|
|
12
12
|
|
|
13
13
|
async function main() {
|
|
14
14
|
// Configuration from environment or hardcoded
|
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
* This example demonstrates how to create a cloud connection with
|
|
5
5
|
* automatic token refresh using ITokenRefresher from auth-broker.
|
|
6
6
|
*
|
|
7
|
-
* When a **401**
|
|
7
|
+
* When a **401** survives the wire's own session recovery, the connection
|
|
8
|
+
* puts it to the provider (`rejected`). `TokenAuthProvider.from` then:
|
|
8
9
|
* 1. Calls tokenRefresher.refreshToken() to get a new token
|
|
9
|
-
* 2.
|
|
10
|
-
* 3.
|
|
11
|
-
*
|
|
10
|
+
* 2. Answers Ok, so the connection authorizes the request again
|
|
11
|
+
* 3. The request is sent exactly once more; a second refusal is an
|
|
12
|
+
* AuthRefusedError carrying the provider's words
|
|
12
13
|
*
|
|
13
14
|
* A **403** is left alone. It means the server authenticated you and refused
|
|
14
15
|
* the action anyway — an authorization gap, not an expired credential — so it
|
|
@@ -19,8 +20,8 @@
|
|
|
19
20
|
const {
|
|
20
21
|
CloudHttpTransport,
|
|
21
22
|
AdtCloudConnector,
|
|
22
|
-
TokenAuthProvider,
|
|
23
23
|
} = require('@mcp-abap-adt/connection');
|
|
24
|
+
const { TokenAuthProvider } = require('@mcp-abap-adt/auth-providers');
|
|
24
25
|
// const { AuthBroker } = require('@mcp-abap-adt/auth-broker');
|
|
25
26
|
|
|
26
27
|
// Simple logger
|
|
@@ -66,12 +67,12 @@ async function main() {
|
|
|
66
67
|
jwtToken: initialToken,
|
|
67
68
|
};
|
|
68
69
|
|
|
69
|
-
// The refresher IS the credential:
|
|
70
|
-
// every
|
|
71
|
-
//
|
|
70
|
+
// The refresher IS the credential: the provider asks it for a token before
|
|
71
|
+
// every attempt and renews when the system refuses one. `.fixed(token)` would
|
|
72
|
+
// be a token with nothing behind it.
|
|
72
73
|
const connection = new AdtCloudConnector(
|
|
73
74
|
config,
|
|
74
|
-
|
|
75
|
+
TokenAuthProvider.from(tokenRefresher),
|
|
75
76
|
new CloudHttpTransport(() => ({}), console, {
|
|
76
77
|
client: config.client,
|
|
77
78
|
baseUrl: config.url,
|
|
@@ -82,12 +83,10 @@ async function main() {
|
|
|
82
83
|
try {
|
|
83
84
|
await connection.connect();
|
|
84
85
|
|
|
85
|
-
//
|
|
86
|
-
// 403 arrives as-is — read
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
// request would fail with ADT_SESSION_REPLACED rather than continue on a
|
|
90
|
-
// session your lock is not in.
|
|
86
|
+
// If a 401 survives the session recovery, the provider is asked once and
|
|
87
|
+
// the request is retried once. A 403 arrives as-is — read
|
|
88
|
+
// err.response.status and err.response.data to see which authorization
|
|
89
|
+
// object the server named.
|
|
91
90
|
const response = await connection.makeAdtRequest({
|
|
92
91
|
method: 'GET',
|
|
93
92
|
url: '/sap/bc/adt/discovery',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-abap-adt/connection",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.2",
|
|
4
4
|
"description": "ABAP connection layer for MCP ABAP ADT server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"check:pack": "node scripts/check-pack.mjs"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
|
-
"node": "
|
|
53
|
+
"node": "^22 || ^24 || ^26"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@mcp-abap-adt/interfaces-adt-connection": "^1.0.0",
|
|
57
|
-
"@mcp-abap-adt/interfaces-auth": "^
|
|
58
|
-
"@mcp-abap-adt/interfaces-auth-sap": "^1.0
|
|
57
|
+
"@mcp-abap-adt/interfaces-auth": "^3.0.0",
|
|
58
|
+
"@mcp-abap-adt/interfaces-auth-sap": "^1.1.0",
|
|
59
59
|
"@mcp-abap-adt/interfaces-network": "^2.0.0",
|
|
60
60
|
"@mcp-abap-adt/interfaces-utils": "^1.1.0",
|
|
61
61
|
"axios": "^1.16.0",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@biomejs/biome": "^2.3.14",
|
|
70
|
+
"@mcp-abap-adt/auth-providers": "^5.0.1",
|
|
70
71
|
"@types/jest": "^30.0.0",
|
|
71
72
|
"@types/node": "^25.2.3",
|
|
72
73
|
"dotenv": "^17.3.1",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ICertificateMaterial } from '@mcp-abap-adt/interfaces-auth';
|
|
2
|
-
import type { ICertificateMaterialLoader, ISapConfig } from '@mcp-abap-adt/interfaces-auth-sap';
|
|
3
|
-
export declare class FileCertificateMaterialLoader implements ICertificateMaterialLoader {
|
|
4
|
-
load(config: ISapConfig): Promise<ICertificateMaterial>;
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=FileCertificateMaterialLoader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FileCertificateMaterialLoader.d.ts","sourceRoot":"","sources":["../../src/auth/FileCertificateMaterialLoader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,EACV,0BAA0B,EAC1B,UAAU,EACX,MAAM,mCAAmC,CAAC;AAE3C,qBAAa,6BACX,YAAW,0BAA0B;IAE/B,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAyB9D"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileCertificateMaterialLoader = void 0;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
class FileCertificateMaterialLoader {
|
|
6
|
-
async load(config) {
|
|
7
|
-
const hasPem = !!(config.certPath || config.certKeyPath); // any PEM-style field present
|
|
8
|
-
const hasPfx = !!config.certPfxPath;
|
|
9
|
-
if (hasPem && hasPfx) {
|
|
10
|
-
throw new Error('Certificate auth: provide either PEM (certPath+certKeyPath) OR certPfxPath, not both.');
|
|
11
|
-
}
|
|
12
|
-
if (hasPfx) {
|
|
13
|
-
return {
|
|
14
|
-
pfx: await (0, promises_1.readFile)(config.certPfxPath),
|
|
15
|
-
passphrase: config.certPassphrase,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
if (config.certPath && config.certKeyPath) {
|
|
19
|
-
return {
|
|
20
|
-
cert: await (0, promises_1.readFile)(config.certPath),
|
|
21
|
-
key: await (0, promises_1.readFile)(config.certKeyPath),
|
|
22
|
-
passphrase: config.certPassphrase,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
throw new Error('Certificate auth requires certPfxPath OR (certPath AND certKeyPath).');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.FileCertificateMaterialLoader = FileCertificateMaterialLoader;
|
package/dist/auth/ntlm.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detect whether a WWW-Authenticate header (or a Negotiate challenge token) indicates NTLM.
|
|
3
|
-
* NTLM is rejected: only Kerberos/SPNEGO Negotiate is acceptable.
|
|
4
|
-
*
|
|
5
|
-
* Two cases:
|
|
6
|
-
* - the header offers the NTLM scheme directly: `WWW-Authenticate: NTLM`
|
|
7
|
-
* - an NTLM token tunneled via Negotiate: `Negotiate <base64>` where the base64 decodes to
|
|
8
|
-
* bytes starting with the NTLM signature "NTLMSSP\0" (base64 prefix "TlRMTVNTUAA").
|
|
9
|
-
*/
|
|
10
|
-
export declare function isNtlmChallenge(wwwAuthenticate: string | undefined): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* `Negotiate <gssapi-data>` — the server has handed back a token for the client
|
|
13
|
-
* to feed into its GSS context and retry (RFC 4559 continuation).
|
|
14
|
-
*/
|
|
15
|
-
export declare function isNegotiateContinuation(wwwAuthenticate: string | undefined): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* A bare `Negotiate`, with no token.
|
|
18
|
-
*
|
|
19
|
-
* Told apart from a continuation deliberately: once the client has ALREADY sent
|
|
20
|
-
* its initial Authorization, a bare challenge is the server declining it — the
|
|
21
|
-
* credentials were not accepted. There is no server token here, so nothing
|
|
22
|
-
* could be stepped even by a client that supports multi-leg. Diagnosing the two
|
|
23
|
-
* alike sends the reader after the wrong problem.
|
|
24
|
-
*/
|
|
25
|
-
export declare function isBareNegotiateChallenge(wwwAuthenticate: string | undefined): boolean;
|
|
26
|
-
//# sourceMappingURL=ntlm.d.ts.map
|
package/dist/auth/ntlm.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ntlm.d.ts","sourceRoot":"","sources":["../../src/auth/ntlm.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAiB5E;AAcD;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,MAAM,GAAG,SAAS,GAClC,OAAO,CAKT;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,MAAM,GAAG,SAAS,GAClC,OAAO,CAIT"}
|
package/dist/auth/ntlm.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNtlmChallenge = isNtlmChallenge;
|
|
4
|
-
exports.isNegotiateContinuation = isNegotiateContinuation;
|
|
5
|
-
exports.isBareNegotiateChallenge = isBareNegotiateChallenge;
|
|
6
|
-
/**
|
|
7
|
-
* Detect whether a WWW-Authenticate header (or a Negotiate challenge token) indicates NTLM.
|
|
8
|
-
* NTLM is rejected: only Kerberos/SPNEGO Negotiate is acceptable.
|
|
9
|
-
*
|
|
10
|
-
* Two cases:
|
|
11
|
-
* - the header offers the NTLM scheme directly: `WWW-Authenticate: NTLM`
|
|
12
|
-
* - an NTLM token tunneled via Negotiate: `Negotiate <base64>` where the base64 decodes to
|
|
13
|
-
* bytes starting with the NTLM signature "NTLMSSP\0" (base64 prefix "TlRMTVNTUAA").
|
|
14
|
-
*/
|
|
15
|
-
function isNtlmChallenge(wwwAuthenticate) {
|
|
16
|
-
if (!wwwAuthenticate)
|
|
17
|
-
return false;
|
|
18
|
-
const value = wwwAuthenticate.trim();
|
|
19
|
-
if (!value)
|
|
20
|
-
return false;
|
|
21
|
-
// Split on commas to handle multiple offered schemes, e.g. "Negotiate, NTLM"
|
|
22
|
-
const parts = value.split(',').map((p) => p.trim());
|
|
23
|
-
for (const part of parts) {
|
|
24
|
-
const lower = part.toLowerCase();
|
|
25
|
-
// direct NTLM scheme offer (word-boundary, not e.g. "Negotiate")
|
|
26
|
-
if (/^ntlm\b/i.test(part))
|
|
27
|
-
return true;
|
|
28
|
-
// NTLM tunneled inside a Negotiate token
|
|
29
|
-
if (lower.startsWith('negotiate ')) {
|
|
30
|
-
const token = part.slice('negotiate '.length).trim();
|
|
31
|
-
if (token.startsWith('TlRMTVNTUAA'))
|
|
32
|
-
return true; // base64("NTLMSSP\0")
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* A `Negotiate` challenge that is not NTLM in disguise. Says nothing about
|
|
39
|
-
* whether it carries a token — callers that care must ask which kind it is.
|
|
40
|
-
*/
|
|
41
|
-
function isNegotiate(wwwAuthenticate) {
|
|
42
|
-
if (!wwwAuthenticate)
|
|
43
|
-
return false;
|
|
44
|
-
if (isNtlmChallenge(wwwAuthenticate))
|
|
45
|
-
return false;
|
|
46
|
-
return wwwAuthenticate
|
|
47
|
-
.split(',')
|
|
48
|
-
.some((part) => /^negotiate\b/i.test(part.trim()));
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* `Negotiate <gssapi-data>` — the server has handed back a token for the client
|
|
52
|
-
* to feed into its GSS context and retry (RFC 4559 continuation).
|
|
53
|
-
*/
|
|
54
|
-
function isNegotiateContinuation(wwwAuthenticate) {
|
|
55
|
-
if (!isNegotiate(wwwAuthenticate))
|
|
56
|
-
return false;
|
|
57
|
-
return wwwAuthenticate
|
|
58
|
-
.split(',')
|
|
59
|
-
.some((part) => /^negotiate\s+\S/i.test(part.trim()));
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* A bare `Negotiate`, with no token.
|
|
63
|
-
*
|
|
64
|
-
* Told apart from a continuation deliberately: once the client has ALREADY sent
|
|
65
|
-
* its initial Authorization, a bare challenge is the server declining it — the
|
|
66
|
-
* credentials were not accepted. There is no server token here, so nothing
|
|
67
|
-
* could be stepped even by a client that supports multi-leg. Diagnosing the two
|
|
68
|
-
* alike sends the reader after the wrong problem.
|
|
69
|
-
*/
|
|
70
|
-
function isBareNegotiateChallenge(wwwAuthenticate) {
|
|
71
|
-
return (isNegotiate(wwwAuthenticate) && !isNegotiateContinuation(wwwAuthenticate));
|
|
72
|
-
}
|