@muze-nl/metro-oidc 0.2.0 → 0.3.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/browser.js +40 -156
- package/dist/browser.js.map +2 -2
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +3 -3
- package/package.json +3 -3
- package/src/oidc.discovery.mjs +1 -1
- package/src/oidc.register.mjs +1 -1
- package/src/oidcmw.mjs +1 -0
package/dist/browser.js
CHANGED
|
@@ -107,12 +107,7 @@
|
|
|
107
107
|
}
|
|
108
108
|
const metrofetch = async function browserFetch(req2) {
|
|
109
109
|
if (req2[Symbol.metroProxy]) {
|
|
110
|
-
|
|
111
|
-
let body = req2.body[Symbol.metroSource];
|
|
112
|
-
req2 = new Request(req2[Symbol.metroSource], { body });
|
|
113
|
-
} else {
|
|
114
|
-
req2 = req2[Symbol.metroSource];
|
|
115
|
-
}
|
|
110
|
+
req2 = req2[Symbol.metroSource];
|
|
116
111
|
}
|
|
117
112
|
const res = await fetch(req2);
|
|
118
113
|
return response(res);
|
|
@@ -149,103 +144,6 @@
|
|
|
149
144
|
function client(...options) {
|
|
150
145
|
return new Client(...options);
|
|
151
146
|
}
|
|
152
|
-
function bodyProxy(body, r) {
|
|
153
|
-
let source = r.body;
|
|
154
|
-
if (!source) {
|
|
155
|
-
if (body === null) {
|
|
156
|
-
source = new ReadableStream();
|
|
157
|
-
} else if (body instanceof ReadableStream) {
|
|
158
|
-
source = body;
|
|
159
|
-
} else if (body instanceof Blob) {
|
|
160
|
-
source = body.stream();
|
|
161
|
-
} else {
|
|
162
|
-
source = new ReadableStream({
|
|
163
|
-
start(controller) {
|
|
164
|
-
let chunk;
|
|
165
|
-
switch (typeof body) {
|
|
166
|
-
case "object":
|
|
167
|
-
if (typeof body.toString == "function") {
|
|
168
|
-
chunk = body.toString();
|
|
169
|
-
} else if (body instanceof FormData) {
|
|
170
|
-
chunk = new URLSearchParams(body).toString();
|
|
171
|
-
} else if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {
|
|
172
|
-
chunk = body;
|
|
173
|
-
} else {
|
|
174
|
-
throw metroError("Cannot convert body to ReadableStream", body);
|
|
175
|
-
}
|
|
176
|
-
break;
|
|
177
|
-
case "string":
|
|
178
|
-
case "number":
|
|
179
|
-
case "boolean":
|
|
180
|
-
chunk = body;
|
|
181
|
-
break;
|
|
182
|
-
default:
|
|
183
|
-
throw metroError("Cannot convert body to ReadableStream", body);
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
controller.enqueue(chunk);
|
|
187
|
-
controller.close();
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return new Proxy(source, {
|
|
193
|
-
get(target, prop, receiver) {
|
|
194
|
-
switch (prop) {
|
|
195
|
-
case Symbol.metroProxy:
|
|
196
|
-
return true;
|
|
197
|
-
break;
|
|
198
|
-
case Symbol.metroSource:
|
|
199
|
-
return body;
|
|
200
|
-
break;
|
|
201
|
-
case "toString":
|
|
202
|
-
return function() {
|
|
203
|
-
return "" + body;
|
|
204
|
-
};
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
if (body && typeof body == "object") {
|
|
208
|
-
if (prop in body) {
|
|
209
|
-
if (typeof body[prop] == "function") {
|
|
210
|
-
return function(...args) {
|
|
211
|
-
return body[prop].apply(body, args);
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
return body[prop];
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (prop in target && prop != "toString") {
|
|
218
|
-
if (typeof target[prop] == "function") {
|
|
219
|
-
return function(...args) {
|
|
220
|
-
return target[prop].apply(target, args);
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
return target[prop];
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
has(target, prop) {
|
|
227
|
-
if (body && typeof body == "object") {
|
|
228
|
-
return prop in body;
|
|
229
|
-
} else {
|
|
230
|
-
return prop in target;
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
ownKeys(target) {
|
|
234
|
-
if (body && typeof body == "object") {
|
|
235
|
-
return Reflect.ownKeys(body);
|
|
236
|
-
} else {
|
|
237
|
-
return Reflect.ownKeys(target);
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
getOwnPropertyDescriptor(target, prop) {
|
|
241
|
-
if (body && typeof body == "object") {
|
|
242
|
-
return Object.getOwnPropertyDescriptor(body, prop);
|
|
243
|
-
} else {
|
|
244
|
-
return Object.getOwnPropertyDescriptor(target, prop);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
147
|
function getRequestParams(req, current) {
|
|
250
148
|
let params2 = current || {};
|
|
251
149
|
if (!params2.url && current.url) {
|
|
@@ -275,7 +173,7 @@
|
|
|
275
173
|
value = value[Symbol.metroSource];
|
|
276
174
|
}
|
|
277
175
|
if (typeof value == "function") {
|
|
278
|
-
value(params2[prop], params2);
|
|
176
|
+
params2[prop] = value(params2[prop], params2);
|
|
279
177
|
} else {
|
|
280
178
|
if (prop == "url") {
|
|
281
179
|
params2.url = url(params2.url, value);
|
|
@@ -292,6 +190,9 @@
|
|
|
292
190
|
}
|
|
293
191
|
}
|
|
294
192
|
}
|
|
193
|
+
if (req instanceof Request && req.data) {
|
|
194
|
+
params2.body = req.data;
|
|
195
|
+
}
|
|
295
196
|
return params2;
|
|
296
197
|
}
|
|
297
198
|
function request(...options) {
|
|
@@ -309,10 +210,10 @@
|
|
|
309
210
|
Object.assign(requestParams, getRequestParams(option, requestParams));
|
|
310
211
|
}
|
|
311
212
|
}
|
|
312
|
-
let
|
|
313
|
-
if (
|
|
314
|
-
if (typeof
|
|
315
|
-
requestParams.body = JSON.stringify(
|
|
213
|
+
let data = requestParams.body;
|
|
214
|
+
if (data) {
|
|
215
|
+
if (typeof data == "object" && !(data instanceof String) && !(data instanceof ReadableStream) && !(data instanceof Blob) && !(data instanceof ArrayBuffer) && !(data instanceof DataView) && !(data instanceof FormData) && !(data instanceof URLSearchParams) && (typeof TypedArray == "undefined" || !(data instanceof TypedArray))) {
|
|
216
|
+
requestParams.body = JSON.stringify(data);
|
|
316
217
|
}
|
|
317
218
|
}
|
|
318
219
|
let r = new Request(requestParams.url, requestParams);
|
|
@@ -328,25 +229,21 @@
|
|
|
328
229
|
break;
|
|
329
230
|
case "with":
|
|
330
231
|
return function(...options2) {
|
|
331
|
-
if (
|
|
332
|
-
options2.unshift({ body });
|
|
232
|
+
if (data) {
|
|
233
|
+
options2.unshift({ body: data });
|
|
333
234
|
}
|
|
334
235
|
return request(target, ...options2);
|
|
335
236
|
};
|
|
336
237
|
break;
|
|
337
238
|
case "body":
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (body) {
|
|
342
|
-
if (body[Symbol.metroProxy]) {
|
|
343
|
-
return body;
|
|
344
|
-
}
|
|
345
|
-
return bodyProxy(body, target);
|
|
346
|
-
}
|
|
239
|
+
break;
|
|
240
|
+
case "data":
|
|
241
|
+
return data;
|
|
347
242
|
break;
|
|
348
243
|
}
|
|
349
244
|
if (target[prop] instanceof Function) {
|
|
245
|
+
if (prop === "clone") {
|
|
246
|
+
}
|
|
350
247
|
return target[prop].bind(target);
|
|
351
248
|
}
|
|
352
249
|
return target[prop];
|
|
@@ -367,7 +264,7 @@
|
|
|
367
264
|
value = value[Symbol.metroSource];
|
|
368
265
|
}
|
|
369
266
|
if (typeof value == "function") {
|
|
370
|
-
value(params2[prop], params2);
|
|
267
|
+
params2[prop] = value(params2[prop], params2);
|
|
371
268
|
} else {
|
|
372
269
|
if (prop == "url") {
|
|
373
270
|
params2.url = new URL(value, params2.url || "https://localhost/");
|
|
@@ -376,6 +273,9 @@
|
|
|
376
273
|
}
|
|
377
274
|
}
|
|
378
275
|
}
|
|
276
|
+
if (res instanceof Response && res.data) {
|
|
277
|
+
params2.body = res.data;
|
|
278
|
+
}
|
|
379
279
|
return params2;
|
|
380
280
|
}
|
|
381
281
|
function response(...options) {
|
|
@@ -393,6 +293,10 @@
|
|
|
393
293
|
}
|
|
394
294
|
}
|
|
395
295
|
}
|
|
296
|
+
let data = void 0;
|
|
297
|
+
if (responseParams.body) {
|
|
298
|
+
data = responseParams.body;
|
|
299
|
+
}
|
|
396
300
|
let r = new Response(responseParams.body, responseParams);
|
|
397
301
|
Object.freeze(r);
|
|
398
302
|
return new Proxy(r, {
|
|
@@ -409,37 +313,17 @@
|
|
|
409
313
|
return response(target, ...options2);
|
|
410
314
|
};
|
|
411
315
|
break;
|
|
412
|
-
case "
|
|
413
|
-
|
|
414
|
-
if (responseParams.body[Symbol.metroProxy]) {
|
|
415
|
-
return responseParams.body;
|
|
416
|
-
}
|
|
417
|
-
return bodyProxy(responseParams.body, target);
|
|
418
|
-
} else {
|
|
419
|
-
return bodyProxy("", target);
|
|
420
|
-
}
|
|
316
|
+
case "data":
|
|
317
|
+
return data;
|
|
421
318
|
break;
|
|
422
319
|
case "ok":
|
|
423
320
|
return target.status >= 200 && target.status < 400;
|
|
424
321
|
break;
|
|
425
|
-
case "headers":
|
|
426
|
-
return target.headers;
|
|
427
|
-
break;
|
|
428
|
-
default:
|
|
429
|
-
if (prop in responseParams && prop != "toString") {
|
|
430
|
-
return responseParams[prop];
|
|
431
|
-
}
|
|
432
|
-
if (prop in target && prop != "toString") {
|
|
433
|
-
if (typeof target[prop] == "function") {
|
|
434
|
-
return function(...args) {
|
|
435
|
-
return target[prop].apply(target, args);
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
return target[prop];
|
|
439
|
-
}
|
|
440
|
-
break;
|
|
441
322
|
}
|
|
442
|
-
|
|
323
|
+
if (typeof target[prop] == "function") {
|
|
324
|
+
return target[prop].bind(target);
|
|
325
|
+
}
|
|
326
|
+
return target[prop];
|
|
443
327
|
}
|
|
444
328
|
});
|
|
445
329
|
}
|
|
@@ -648,9 +532,9 @@
|
|
|
648
532
|
"Accept": "application/json"
|
|
649
533
|
}
|
|
650
534
|
});
|
|
651
|
-
if (req.
|
|
535
|
+
if (req.data && typeof req.data == "object" && !(req.data instanceof ReadableStream)) {
|
|
652
536
|
req = req.with({
|
|
653
|
-
body: JSON.stringify(req.
|
|
537
|
+
body: JSON.stringify(req.data, options.replacer, options.space)
|
|
654
538
|
});
|
|
655
539
|
}
|
|
656
540
|
} else {
|
|
@@ -1000,7 +884,7 @@
|
|
|
1000
884
|
// note: this allows path components in the options.issuer url
|
|
1001
885
|
configURL
|
|
1002
886
|
);
|
|
1003
|
-
const openid_config = response2.
|
|
887
|
+
const openid_config = response2.data;
|
|
1004
888
|
assert(openid_config, openid_provider_metadata);
|
|
1005
889
|
assert(openid_config.issuer, options.issuer);
|
|
1006
890
|
return openid_config;
|
|
@@ -1053,7 +937,7 @@
|
|
|
1053
937
|
let response2 = await options.client.post(options.registration_endpoint, {
|
|
1054
938
|
body: options.client_info
|
|
1055
939
|
});
|
|
1056
|
-
let info = response2.
|
|
940
|
+
let info = response2.data;
|
|
1057
941
|
if (!info.client_id || !info.client_secret) {
|
|
1058
942
|
throw everything_default.metroError("metro.oidc: Error: dynamic registration of client failed, no client_id or client_secret returned", response2);
|
|
1059
943
|
}
|
|
@@ -1638,22 +1522,22 @@
|
|
|
1638
1522
|
});
|
|
1639
1523
|
break;
|
|
1640
1524
|
case "/token/":
|
|
1641
|
-
if (req.
|
|
1525
|
+
if (req.data instanceof URLSearchParams) {
|
|
1642
1526
|
let body = {};
|
|
1643
|
-
req.
|
|
1527
|
+
req.data.forEach((value, key) => body[key] = value);
|
|
1644
1528
|
req = req.with({ body });
|
|
1645
1529
|
}
|
|
1646
1530
|
if (error3 = fails2(req, {
|
|
1647
1531
|
method: "POST",
|
|
1648
|
-
|
|
1532
|
+
data: {
|
|
1649
1533
|
grant_type: oneOf2("refresh_token", "authorization_code")
|
|
1650
1534
|
}
|
|
1651
1535
|
})) {
|
|
1652
1536
|
return everything_default.response(badRequest(error3));
|
|
1653
1537
|
}
|
|
1654
|
-
switch (req.
|
|
1538
|
+
switch (req.data.grant_type) {
|
|
1655
1539
|
case "refresh_token":
|
|
1656
|
-
if (error3 = fails2(req.
|
|
1540
|
+
if (error3 = fails2(req.data, oneOf2({
|
|
1657
1541
|
refresh_token: "mockRefreshToken",
|
|
1658
1542
|
client_id: "mockClientId",
|
|
1659
1543
|
client_secret: "mockClientSecret"
|
|
@@ -1666,7 +1550,7 @@
|
|
|
1666
1550
|
}
|
|
1667
1551
|
break;
|
|
1668
1552
|
case "access_token":
|
|
1669
|
-
if (error3 = fails2(req.
|
|
1553
|
+
if (error3 = fails2(req.data, oneOf2({
|
|
1670
1554
|
client_id: "mockClientId",
|
|
1671
1555
|
client_secret: "mockClientSecret"
|
|
1672
1556
|
}, {
|