@mcp-z/client 1.2.0 → 2.0.0
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/dist/cjs/auth/capability-discovery.js +5 -1
- package/dist/cjs/auth/capability-discovery.js.map +1 -1
- package/dist/cjs/auth/interactive-oauth-flow.d.cts +9 -2
- package/dist/cjs/auth/interactive-oauth-flow.d.ts +9 -2
- package/dist/cjs/auth/interactive-oauth-flow.js +29 -11
- package/dist/cjs/auth/interactive-oauth-flow.js.map +1 -1
- package/dist/cjs/auth/oauth-callback-listener.js +4 -0
- package/dist/cjs/auth/oauth-callback-listener.js.map +1 -1
- package/dist/cjs/auth/types.d.cts +18 -4
- package/dist/cjs/auth/types.d.ts +18 -4
- package/dist/cjs/auth/types.js.map +1 -1
- package/dist/cjs/dcr/dcr-authenticator.d.cts +6 -1
- package/dist/cjs/dcr/dcr-authenticator.d.ts +6 -1
- package/dist/cjs/dcr/dcr-authenticator.js +423 -40
- package/dist/cjs/dcr/dcr-authenticator.js.map +1 -1
- package/dist/cjs/dcr/dynamic-client-registrar.d.cts +2 -2
- package/dist/cjs/dcr/dynamic-client-registrar.d.ts +2 -2
- package/dist/cjs/dcr/dynamic-client-registrar.js +10 -11
- package/dist/cjs/dcr/dynamic-client-registrar.js.map +1 -1
- package/dist/cjs/lib/url-utils.js +2 -2
- package/dist/cjs/lib/url-utils.js.map +1 -1
- package/dist/esm/auth/capability-discovery.js +5 -1
- package/dist/esm/auth/capability-discovery.js.map +1 -1
- package/dist/esm/auth/interactive-oauth-flow.d.ts +9 -2
- package/dist/esm/auth/interactive-oauth-flow.js +28 -10
- package/dist/esm/auth/interactive-oauth-flow.js.map +1 -1
- package/dist/esm/auth/oauth-callback-listener.js +4 -0
- package/dist/esm/auth/oauth-callback-listener.js.map +1 -1
- package/dist/esm/auth/types.d.ts +18 -4
- package/dist/esm/auth/types.js.map +1 -1
- package/dist/esm/dcr/dcr-authenticator.d.ts +6 -1
- package/dist/esm/dcr/dcr-authenticator.js +79 -35
- package/dist/esm/dcr/dcr-authenticator.js.map +1 -1
- package/dist/esm/dcr/dynamic-client-registrar.d.ts +2 -2
- package/dist/esm/dcr/dynamic-client-registrar.js +7 -6
- package/dist/esm/dcr/dynamic-client-registrar.js.map +1 -1
- package/dist/esm/lib/url-utils.js +2 -2
- package/dist/esm/lib/url-utils.js.map +1 -1
- package/package.json +2 -2
|
@@ -17,8 +17,62 @@ var _keyv = /*#__PURE__*/ _interop_require_default(require("keyv"));
|
|
|
17
17
|
var _keyvfile = require("keyv-file");
|
|
18
18
|
var _discoveryfetchts = require("../auth/discovery-fetch.js");
|
|
19
19
|
var _interactiveoauthflowts = require("../auth/interactive-oauth-flow.js");
|
|
20
|
+
var _urlutilsts = require("../lib/url-utils.js");
|
|
20
21
|
var _loggerts = require("../utils/logger.js");
|
|
21
22
|
var _dynamicclientregistrarts = require("./dynamic-client-registrar.js");
|
|
23
|
+
function _array_like_to_array(arr, len) {
|
|
24
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
25
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
26
|
+
return arr2;
|
|
27
|
+
}
|
|
28
|
+
function _array_with_holes(arr) {
|
|
29
|
+
if (Array.isArray(arr)) return arr;
|
|
30
|
+
}
|
|
31
|
+
function _assert_this_initialized(self) {
|
|
32
|
+
if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
33
|
+
return self;
|
|
34
|
+
}
|
|
35
|
+
function _async_iterator(iterable) {
|
|
36
|
+
var method, async, sync, retry = 2;
|
|
37
|
+
for("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;){
|
|
38
|
+
if (async && null != (method = iterable[async])) return method.call(iterable);
|
|
39
|
+
if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
|
|
40
|
+
async = "@@asyncIterator", sync = "@@iterator";
|
|
41
|
+
}
|
|
42
|
+
throw new TypeError("Object is not async iterable");
|
|
43
|
+
}
|
|
44
|
+
function AsyncFromSyncIterator(s) {
|
|
45
|
+
function AsyncFromSyncIteratorContinuation(r) {
|
|
46
|
+
if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
|
|
47
|
+
var done = r.done;
|
|
48
|
+
return Promise.resolve(r.value).then(function(value) {
|
|
49
|
+
return {
|
|
50
|
+
value: value,
|
|
51
|
+
done: done
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return AsyncFromSyncIterator = function(s) {
|
|
56
|
+
this.s = s, this.n = s.next;
|
|
57
|
+
}, AsyncFromSyncIterator.prototype = {
|
|
58
|
+
s: null,
|
|
59
|
+
n: null,
|
|
60
|
+
next: function() {
|
|
61
|
+
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
62
|
+
},
|
|
63
|
+
return: function(value) {
|
|
64
|
+
var ret = this.s.return;
|
|
65
|
+
return void 0 === ret ? Promise.resolve({
|
|
66
|
+
value: value,
|
|
67
|
+
done: !0
|
|
68
|
+
}) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
|
|
69
|
+
},
|
|
70
|
+
throw: function(value) {
|
|
71
|
+
var thr = this.s.return;
|
|
72
|
+
return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
|
|
73
|
+
}
|
|
74
|
+
}, new AsyncFromSyncIterator(s);
|
|
75
|
+
}
|
|
22
76
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
23
77
|
try {
|
|
24
78
|
var info = gen[key](arg);
|
|
@@ -45,9 +99,59 @@ function _async_to_generator(fn) {
|
|
|
45
99
|
});
|
|
46
100
|
};
|
|
47
101
|
}
|
|
102
|
+
function _call_super(_this, derived, args) {
|
|
103
|
+
derived = _get_prototype_of(derived);
|
|
104
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
105
|
+
}
|
|
48
106
|
function _class_call_check(instance, Constructor) {
|
|
49
107
|
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
|
|
50
108
|
}
|
|
109
|
+
function _construct(Parent, args, Class) {
|
|
110
|
+
if (_is_native_reflect_construct()) _construct = Reflect.construct;
|
|
111
|
+
else {
|
|
112
|
+
_construct = function construct(Parent, args, Class) {
|
|
113
|
+
var a = [
|
|
114
|
+
null
|
|
115
|
+
];
|
|
116
|
+
a.push.apply(a, args);
|
|
117
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
118
|
+
var instance = new Constructor();
|
|
119
|
+
if (Class) _set_prototype_of(instance, Class.prototype);
|
|
120
|
+
return instance;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return _construct.apply(null, arguments);
|
|
124
|
+
}
|
|
125
|
+
function _define_property(obj, key, value) {
|
|
126
|
+
if (key in obj) {
|
|
127
|
+
Object.defineProperty(obj, key, {
|
|
128
|
+
value: value,
|
|
129
|
+
enumerable: true,
|
|
130
|
+
configurable: true,
|
|
131
|
+
writable: true
|
|
132
|
+
});
|
|
133
|
+
} else obj[key] = value;
|
|
134
|
+
return obj;
|
|
135
|
+
}
|
|
136
|
+
function _get_prototype_of(o) {
|
|
137
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
138
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
139
|
+
};
|
|
140
|
+
return _get_prototype_of(o);
|
|
141
|
+
}
|
|
142
|
+
function _inherits(subClass, superClass) {
|
|
143
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
144
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
145
|
+
}
|
|
146
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
147
|
+
constructor: {
|
|
148
|
+
value: subClass,
|
|
149
|
+
writable: true,
|
|
150
|
+
configurable: true
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
154
|
+
}
|
|
51
155
|
function _instanceof(left, right) {
|
|
52
156
|
"@swc/helpers - instanceof";
|
|
53
157
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
@@ -89,6 +193,96 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
89
193
|
if (cache) cache.set(obj, newObj);
|
|
90
194
|
return newObj;
|
|
91
195
|
}
|
|
196
|
+
function _is_native_function(fn) {
|
|
197
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
198
|
+
}
|
|
199
|
+
function _is_native_reflect_construct() {
|
|
200
|
+
try {
|
|
201
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
202
|
+
} catch (_) {}
|
|
203
|
+
return (_is_native_reflect_construct = function() {
|
|
204
|
+
return !!result;
|
|
205
|
+
})();
|
|
206
|
+
}
|
|
207
|
+
function _iterable_to_array_limit(arr, i) {
|
|
208
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
209
|
+
if (_i == null) return;
|
|
210
|
+
var _arr = [];
|
|
211
|
+
var _n = true;
|
|
212
|
+
var _d = false;
|
|
213
|
+
var _s, _e;
|
|
214
|
+
try {
|
|
215
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
216
|
+
_arr.push(_s.value);
|
|
217
|
+
if (i && _arr.length === i) break;
|
|
218
|
+
}
|
|
219
|
+
} catch (err) {
|
|
220
|
+
_d = true;
|
|
221
|
+
_e = err;
|
|
222
|
+
} finally{
|
|
223
|
+
try {
|
|
224
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
225
|
+
} finally{
|
|
226
|
+
if (_d) throw _e;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return _arr;
|
|
230
|
+
}
|
|
231
|
+
function _non_iterable_rest() {
|
|
232
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
233
|
+
}
|
|
234
|
+
function _object_spread(target) {
|
|
235
|
+
for(var i = 1; i < arguments.length; i++){
|
|
236
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
237
|
+
var ownKeys = Object.keys(source);
|
|
238
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
239
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
240
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
ownKeys.forEach(function(key) {
|
|
244
|
+
_define_property(target, key, source[key]);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
return target;
|
|
248
|
+
}
|
|
249
|
+
function ownKeys(object, enumerableOnly) {
|
|
250
|
+
var keys = Object.keys(object);
|
|
251
|
+
if (Object.getOwnPropertySymbols) {
|
|
252
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
253
|
+
if (enumerableOnly) {
|
|
254
|
+
symbols = symbols.filter(function(sym) {
|
|
255
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
keys.push.apply(keys, symbols);
|
|
259
|
+
}
|
|
260
|
+
return keys;
|
|
261
|
+
}
|
|
262
|
+
function _object_spread_props(target, source) {
|
|
263
|
+
source = source != null ? source : {};
|
|
264
|
+
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
265
|
+
else {
|
|
266
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
267
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return target;
|
|
271
|
+
}
|
|
272
|
+
function _possible_constructor_return(self, call) {
|
|
273
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
|
|
274
|
+
return _assert_this_initialized(self);
|
|
275
|
+
}
|
|
276
|
+
function _set_prototype_of(o, p) {
|
|
277
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
278
|
+
o.__proto__ = p;
|
|
279
|
+
return o;
|
|
280
|
+
};
|
|
281
|
+
return _set_prototype_of(o, p);
|
|
282
|
+
}
|
|
283
|
+
function _sliced_to_array(arr, i) {
|
|
284
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
285
|
+
}
|
|
92
286
|
function _ts_generator(thisArg, body) {
|
|
93
287
|
var f, y, t, _ = {
|
|
94
288
|
label: 0,
|
|
@@ -188,9 +382,68 @@ function _ts_generator(thisArg, body) {
|
|
|
188
382
|
};
|
|
189
383
|
}
|
|
190
384
|
}
|
|
385
|
+
function _type_of(obj) {
|
|
386
|
+
"@swc/helpers - typeof";
|
|
387
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
388
|
+
}
|
|
389
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
390
|
+
if (!o) return;
|
|
391
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
392
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
393
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
394
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
395
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
396
|
+
}
|
|
397
|
+
function _wrap_native_super(Class) {
|
|
398
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
399
|
+
_wrap_native_super = function(Class) {
|
|
400
|
+
if (Class === null || !_is_native_function(Class)) return Class;
|
|
401
|
+
if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
|
|
402
|
+
if (typeof _cache !== "undefined") {
|
|
403
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
404
|
+
_cache.set(Class, Wrapper);
|
|
405
|
+
}
|
|
406
|
+
function Wrapper() {
|
|
407
|
+
return _construct(Class, arguments, _get_prototype_of(this).constructor);
|
|
408
|
+
}
|
|
409
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
410
|
+
constructor: {
|
|
411
|
+
value: Wrapper,
|
|
412
|
+
enumerable: false,
|
|
413
|
+
writable: true,
|
|
414
|
+
configurable: true
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
return _set_prototype_of(Wrapper, Class);
|
|
418
|
+
};
|
|
419
|
+
return _wrap_native_super(Class);
|
|
420
|
+
}
|
|
191
421
|
/**
|
|
192
422
|
* Buffer time before token expiry to trigger proactive refresh (5 minutes)
|
|
193
423
|
*/ var REFRESH_BUFFER_MS = 5 * 60 * 1000;
|
|
424
|
+
/** Raised when a credential cannot be bound to, or looked up by, an issuer. */ var CredentialBindingError = /*#__PURE__*/ function(Error1) {
|
|
425
|
+
"use strict";
|
|
426
|
+
_inherits(CredentialBindingError, Error1);
|
|
427
|
+
function CredentialBindingError(message) {
|
|
428
|
+
_class_call_check(this, CredentialBindingError);
|
|
429
|
+
var _this;
|
|
430
|
+
_this = _call_super(this, CredentialBindingError, [
|
|
431
|
+
message
|
|
432
|
+
]);
|
|
433
|
+
_this.name = 'CredentialBindingError';
|
|
434
|
+
return _this;
|
|
435
|
+
}
|
|
436
|
+
return CredentialBindingError;
|
|
437
|
+
}(_wrap_native_super(Error));
|
|
438
|
+
/**
|
|
439
|
+
* The issuer credentials are keyed by, so they can never be presented to a
|
|
440
|
+
* different authorization server even when the resource keeps its URL (SEP-2352).
|
|
441
|
+
*/ function requireIssuer(capabilities) {
|
|
442
|
+
if (!capabilities.issuer) {
|
|
443
|
+
throw new CredentialBindingError('Authorization server metadata has no issuer - credentials cannot be bound to an authorization server (RFC 8414 requires issuer)');
|
|
444
|
+
}
|
|
445
|
+
return capabilities.issuer;
|
|
446
|
+
}
|
|
194
447
|
var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
195
448
|
"use strict";
|
|
196
449
|
function DcrAuthenticator(options) {
|
|
@@ -292,17 +545,19 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
292
545
|
* Self-hosted servers manage their own token storage via /oauth/verify
|
|
293
546
|
*/ _proto.ensureAuthenticatedSelfHosted = function ensureAuthenticatedSelfHosted(baseUrl, capabilities) {
|
|
294
547
|
return _async_to_generator(function() {
|
|
295
|
-
var allowLoopback, dcrTokenKey, tokens, verifyUrl, verifyResponse, verifyData, _error, port, client, flowOptions, verifyUrl1, verifyResponse1, verifyData1, error;
|
|
548
|
+
var allowLoopback, issuer, resource, dcrTokenKey, tokens, verifyUrl, verifyResponse, verifyData, _error, port, client, flowOptions, verifyUrl1, verifyResponse1, verifyData1, error;
|
|
296
549
|
return _ts_generator(this, function(_state) {
|
|
297
550
|
switch(_state.label){
|
|
298
551
|
case 0:
|
|
299
552
|
// Loopback trust for every discovery-derived fetch below, computed from
|
|
300
553
|
// the server we're talking to, never from capabilities' endpoints (see discovery-fetch.ts).
|
|
301
554
|
allowLoopback = (0, _discoveryfetchts.isLoopbackUrl)(baseUrl);
|
|
302
|
-
|
|
555
|
+
issuer = requireIssuer(capabilities);
|
|
556
|
+
resource = (0, _urlutilsts.normalizeUrl)(baseUrl);
|
|
557
|
+
dcrTokenKey = "dcr-tokens:".concat(issuer, ":").concat(resource);
|
|
303
558
|
return [
|
|
304
559
|
4,
|
|
305
|
-
this.
|
|
560
|
+
this.loadTokens(dcrTokenKey, issuer)
|
|
306
561
|
];
|
|
307
562
|
case 1:
|
|
308
563
|
tokens = _state.sent();
|
|
@@ -389,17 +644,7 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
389
644
|
case 10:
|
|
390
645
|
client = _state.sent();
|
|
391
646
|
// Perform OAuth authorization flow with PKCE (RFC 7636)
|
|
392
|
-
flowOptions =
|
|
393
|
-
port: port,
|
|
394
|
-
headless: this.headless,
|
|
395
|
-
redirectUri: this.redirectUri,
|
|
396
|
-
pkce: true,
|
|
397
|
-
logger: this.logger,
|
|
398
|
-
allowLoopback: allowLoopback
|
|
399
|
-
};
|
|
400
|
-
if (capabilities.scopes) {
|
|
401
|
-
flowOptions.scopes = capabilities.scopes;
|
|
402
|
-
}
|
|
647
|
+
flowOptions = this.buildFlowOptions(port, capabilities, issuer, resource, allowLoopback);
|
|
403
648
|
return [
|
|
404
649
|
4,
|
|
405
650
|
this.oauthFlow.performAuthFlow(capabilities.authorizationEndpoint, capabilities.tokenEndpoint, client.clientId, client.clientSecret, flowOptions)
|
|
@@ -451,7 +696,9 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
451
696
|
// Save tokens for future use
|
|
452
697
|
return [
|
|
453
698
|
4,
|
|
454
|
-
this.tokenStore.set(dcrTokenKey, tokens)
|
|
699
|
+
this.tokenStore.set(dcrTokenKey, _object_spread_props(_object_spread({}, tokens), {
|
|
700
|
+
issuer: issuer
|
|
701
|
+
}))
|
|
455
702
|
];
|
|
456
703
|
case 17:
|
|
457
704
|
_state.sent();
|
|
@@ -466,16 +713,18 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
466
713
|
};
|
|
467
714
|
/** Handles authentication for external (non-self-hosted) OAuth providers. */ _proto.ensureAuthenticatedExternal = function ensureAuthenticatedExternal(baseUrl, capabilities) {
|
|
468
715
|
return _async_to_generator(function() {
|
|
469
|
-
var allowLoopback, tokenKey, tokens, _error, port, client, flowOptions;
|
|
716
|
+
var allowLoopback, issuer, resource, tokenKey, tokens, _error, port, client, flowOptions;
|
|
470
717
|
return _ts_generator(this, function(_state) {
|
|
471
718
|
switch(_state.label){
|
|
472
719
|
case 0:
|
|
473
720
|
// See ensureAuthenticatedSelfHosted - same loopback trust rule.
|
|
474
721
|
allowLoopback = (0, _discoveryfetchts.isLoopbackUrl)(baseUrl);
|
|
475
|
-
|
|
722
|
+
issuer = requireIssuer(capabilities);
|
|
723
|
+
resource = (0, _urlutilsts.normalizeUrl)(baseUrl);
|
|
724
|
+
tokenKey = "tokens:".concat(issuer, ":").concat(resource);
|
|
476
725
|
return [
|
|
477
726
|
4,
|
|
478
|
-
this.
|
|
727
|
+
this.loadTokens(tokenKey, issuer)
|
|
479
728
|
];
|
|
480
729
|
case 1:
|
|
481
730
|
tokens = _state.sent();
|
|
@@ -498,13 +747,15 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
498
747
|
]);
|
|
499
748
|
return [
|
|
500
749
|
4,
|
|
501
|
-
this.refreshTokens(tokens, capabilities.tokenEndpoint, allowLoopback)
|
|
750
|
+
this.refreshTokens(tokens, capabilities.tokenEndpoint, resource, allowLoopback)
|
|
502
751
|
];
|
|
503
752
|
case 3:
|
|
504
753
|
tokens = _state.sent();
|
|
505
754
|
return [
|
|
506
755
|
4,
|
|
507
|
-
this.tokenStore.set(tokenKey, tokens)
|
|
756
|
+
this.tokenStore.set(tokenKey, _object_spread_props(_object_spread({}, tokens), {
|
|
757
|
+
issuer: issuer
|
|
758
|
+
}))
|
|
508
759
|
];
|
|
509
760
|
case 4:
|
|
510
761
|
_state.sent();
|
|
@@ -556,17 +807,7 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
556
807
|
case 9:
|
|
557
808
|
client = _state.sent();
|
|
558
809
|
// Perform OAuth authorization flow with PKCE (RFC 7636)
|
|
559
|
-
flowOptions =
|
|
560
|
-
port: port,
|
|
561
|
-
headless: this.headless,
|
|
562
|
-
redirectUri: this.redirectUri,
|
|
563
|
-
pkce: true,
|
|
564
|
-
logger: this.logger,
|
|
565
|
-
allowLoopback: allowLoopback
|
|
566
|
-
};
|
|
567
|
-
if (capabilities.scopes) {
|
|
568
|
-
flowOptions.scopes = capabilities.scopes;
|
|
569
|
-
}
|
|
810
|
+
flowOptions = this.buildFlowOptions(port, capabilities, issuer, resource, allowLoopback);
|
|
570
811
|
return [
|
|
571
812
|
4,
|
|
572
813
|
this.oauthFlow.performAuthFlow(capabilities.authorizationEndpoint, capabilities.tokenEndpoint, client.clientId, client.clientSecret, flowOptions)
|
|
@@ -576,7 +817,9 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
576
817
|
// Save tokens for future use
|
|
577
818
|
return [
|
|
578
819
|
4,
|
|
579
|
-
this.tokenStore.set(tokenKey, tokens)
|
|
820
|
+
this.tokenStore.set(tokenKey, _object_spread_props(_object_spread({}, tokens), {
|
|
821
|
+
issuer: issuer
|
|
822
|
+
}))
|
|
580
823
|
];
|
|
581
824
|
case 11:
|
|
582
825
|
_state.sent();
|
|
@@ -591,9 +834,10 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
591
834
|
};
|
|
592
835
|
/**
|
|
593
836
|
* Refreshes an access token using a refresh token.
|
|
837
|
+
* @param resource - Canonical resource server URI, audience-binding the token (RFC 8707).
|
|
594
838
|
* @param allowLoopback - Loopback trust grant computed from the server actually being talked to (SSRF mitigation, see discovery-fetch.ts). Defaults to `false`.
|
|
595
|
-
*/ _proto.refreshTokens = function refreshTokens(tokens, tokenEndpoint) {
|
|
596
|
-
var allowLoopback = arguments.length >
|
|
839
|
+
*/ _proto.refreshTokens = function refreshTokens(tokens, tokenEndpoint, resource) {
|
|
840
|
+
var allowLoopback = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
|
|
597
841
|
return _async_to_generator(function() {
|
|
598
842
|
return _ts_generator(this, function(_state) {
|
|
599
843
|
switch(_state.label){
|
|
@@ -609,7 +853,7 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
609
853
|
}
|
|
610
854
|
return [
|
|
611
855
|
4,
|
|
612
|
-
this.oauthFlow.refreshTokens(tokenEndpoint, tokens.refreshToken, tokens.clientId, tokens.clientSecret, allowLoopback)
|
|
856
|
+
this.oauthFlow.refreshTokens(tokenEndpoint, tokens.refreshToken, tokens.clientId, tokens.clientSecret, resource, allowLoopback)
|
|
613
857
|
];
|
|
614
858
|
case 1:
|
|
615
859
|
return [
|
|
@@ -621,20 +865,106 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
621
865
|
}).call(this);
|
|
622
866
|
};
|
|
623
867
|
/**
|
|
624
|
-
*
|
|
868
|
+
* Deletes both stored token families for a server, across every issuer they were bound to.
|
|
869
|
+
* @throws CredentialBindingError if the configured store cannot enumerate keys.
|
|
625
870
|
*/ _proto.deleteTokens = function deleteTokens(baseUrl) {
|
|
626
871
|
return _async_to_generator(function() {
|
|
627
|
-
var
|
|
872
|
+
var suffix, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, _value1, key, err;
|
|
628
873
|
return _ts_generator(this, function(_state) {
|
|
629
874
|
switch(_state.label){
|
|
630
875
|
case 0:
|
|
631
|
-
|
|
876
|
+
suffix = ":".concat((0, _urlutilsts.normalizeUrl)(baseUrl));
|
|
877
|
+
if (!this.tokenStore.iterator) {
|
|
878
|
+
throw new CredentialBindingError('Token store does not support key enumeration, which issuer-keyed credentials require');
|
|
879
|
+
}
|
|
880
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
881
|
+
_state.label = 1;
|
|
882
|
+
case 1:
|
|
883
|
+
_state.trys.push([
|
|
884
|
+
1,
|
|
885
|
+
7,
|
|
886
|
+
8,
|
|
887
|
+
13
|
|
888
|
+
]);
|
|
889
|
+
_iterator = _async_iterator(this.tokenStore.iterator(this.tokenStore.namespace));
|
|
890
|
+
_state.label = 2;
|
|
891
|
+
case 2:
|
|
632
892
|
return [
|
|
633
893
|
4,
|
|
634
|
-
|
|
894
|
+
_iterator.next()
|
|
635
895
|
];
|
|
636
|
-
case
|
|
896
|
+
case 3:
|
|
897
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
898
|
+
3,
|
|
899
|
+
6
|
|
900
|
+
];
|
|
901
|
+
_value = _step.value;
|
|
902
|
+
_value1 = _sliced_to_array(_value, 1), key = _value1[0];
|
|
903
|
+
if (!(typeof key === 'string' && (key.startsWith('tokens:') || key.startsWith('dcr-tokens:')) && key.endsWith(suffix))) return [
|
|
904
|
+
3,
|
|
905
|
+
5
|
|
906
|
+
];
|
|
907
|
+
return [
|
|
908
|
+
4,
|
|
909
|
+
this.tokenStore.delete(key)
|
|
910
|
+
];
|
|
911
|
+
case 4:
|
|
912
|
+
_state.sent();
|
|
913
|
+
_state.label = 5;
|
|
914
|
+
case 5:
|
|
915
|
+
_iteratorAbruptCompletion = false;
|
|
916
|
+
return [
|
|
917
|
+
3,
|
|
918
|
+
2
|
|
919
|
+
];
|
|
920
|
+
case 6:
|
|
921
|
+
return [
|
|
922
|
+
3,
|
|
923
|
+
13
|
|
924
|
+
];
|
|
925
|
+
case 7:
|
|
926
|
+
err = _state.sent();
|
|
927
|
+
_didIteratorError = true;
|
|
928
|
+
_iteratorError = err;
|
|
929
|
+
return [
|
|
930
|
+
3,
|
|
931
|
+
13
|
|
932
|
+
];
|
|
933
|
+
case 8:
|
|
934
|
+
_state.trys.push([
|
|
935
|
+
8,
|
|
936
|
+
,
|
|
937
|
+
11,
|
|
938
|
+
12
|
|
939
|
+
]);
|
|
940
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
941
|
+
3,
|
|
942
|
+
10
|
|
943
|
+
];
|
|
944
|
+
return [
|
|
945
|
+
4,
|
|
946
|
+
_iterator.return()
|
|
947
|
+
];
|
|
948
|
+
case 9:
|
|
637
949
|
_state.sent();
|
|
950
|
+
_state.label = 10;
|
|
951
|
+
case 10:
|
|
952
|
+
return [
|
|
953
|
+
3,
|
|
954
|
+
12
|
|
955
|
+
];
|
|
956
|
+
case 11:
|
|
957
|
+
if (_didIteratorError) {
|
|
958
|
+
throw _iteratorError;
|
|
959
|
+
}
|
|
960
|
+
return [
|
|
961
|
+
7
|
|
962
|
+
];
|
|
963
|
+
case 12:
|
|
964
|
+
return [
|
|
965
|
+
7
|
|
966
|
+
];
|
|
967
|
+
case 13:
|
|
638
968
|
this.logger.debug("\uD83D\uDDD1️ Deleted tokens for ".concat(baseUrl));
|
|
639
969
|
return [
|
|
640
970
|
2
|
|
@@ -643,6 +973,59 @@ var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
|
643
973
|
});
|
|
644
974
|
}).call(this);
|
|
645
975
|
};
|
|
976
|
+
/** Discards a stored credential that is not bound to `issuer` (SEP-2352), including one stored before issuer binding existed. */ _proto.loadTokens = function loadTokens(key, issuer) {
|
|
977
|
+
return _async_to_generator(function() {
|
|
978
|
+
var tokens;
|
|
979
|
+
return _ts_generator(this, function(_state) {
|
|
980
|
+
switch(_state.label){
|
|
981
|
+
case 0:
|
|
982
|
+
return [
|
|
983
|
+
4,
|
|
984
|
+
this.tokenStore.get(key)
|
|
985
|
+
];
|
|
986
|
+
case 1:
|
|
987
|
+
tokens = _state.sent();
|
|
988
|
+
if (!tokens) return [
|
|
989
|
+
2,
|
|
990
|
+
undefined
|
|
991
|
+
];
|
|
992
|
+
if (tokens.issuer === issuer) return [
|
|
993
|
+
2,
|
|
994
|
+
tokens
|
|
995
|
+
];
|
|
996
|
+
this.logger.debug('🔑 Stored credential is not bound to the discovered issuer, re-authorizing');
|
|
997
|
+
return [
|
|
998
|
+
4,
|
|
999
|
+
this.tokenStore.delete(key)
|
|
1000
|
+
];
|
|
1001
|
+
case 2:
|
|
1002
|
+
_state.sent();
|
|
1003
|
+
return [
|
|
1004
|
+
2,
|
|
1005
|
+
undefined
|
|
1006
|
+
];
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
}).call(this);
|
|
1010
|
+
};
|
|
1011
|
+
_proto.buildFlowOptions = function buildFlowOptions(port, capabilities, issuer, resource, allowLoopback) {
|
|
1012
|
+
var _capabilities_authorizationResponseIssSupported;
|
|
1013
|
+
var flowOptions = {
|
|
1014
|
+
port: port,
|
|
1015
|
+
issuer: issuer,
|
|
1016
|
+
resource: resource,
|
|
1017
|
+
headless: this.headless,
|
|
1018
|
+
redirectUri: this.redirectUri,
|
|
1019
|
+
pkce: true,
|
|
1020
|
+
logger: this.logger,
|
|
1021
|
+
allowLoopback: allowLoopback,
|
|
1022
|
+
authorizationResponseIssSupported: (_capabilities_authorizationResponseIssSupported = capabilities.authorizationResponseIssSupported) !== null && _capabilities_authorizationResponseIssSupported !== void 0 ? _capabilities_authorizationResponseIssSupported : false
|
|
1023
|
+
};
|
|
1024
|
+
if (capabilities.scopes) {
|
|
1025
|
+
flowOptions.scopes = capabilities.scopes;
|
|
1026
|
+
}
|
|
1027
|
+
return flowOptions;
|
|
1028
|
+
};
|
|
646
1029
|
return DcrAuthenticator;
|
|
647
1030
|
}();
|
|
648
1031
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|