@muze-nl/metro-oidc 0.4.0 → 0.5.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 CHANGED
@@ -8,7 +8,9 @@
8
8
  // node_modules/@muze-nl/metro/src/metro.mjs
9
9
  var metro_exports = {};
10
10
  __export(metro_exports, {
11
+ Client: () => Client,
11
12
  client: () => client,
13
+ deepClone: () => deepClone,
12
14
  formdata: () => formdata,
13
15
  metroError: () => metroError,
14
16
  request: () => request,
@@ -24,10 +26,10 @@
24
26
  Symbol.metroSource = Symbol("source");
25
27
  }
26
28
  var Client = class _Client {
27
- #options = {
28
- url: typeof window != "undefined" ? window.location : "https://localhost"
29
+ clientOptions = {
30
+ url: typeof window != "undefined" ? window.location : "https://localhost",
31
+ verbs: ["get", "post", "put", "delete", "patch", "head", "options", "query"]
29
32
  };
30
- #verbs = ["get", "post", "put", "delete", "patch", "head", "options", "query"];
31
33
  static tracers = {};
32
34
  /**
33
35
  * @typedef {Object} ClientOptions
@@ -42,9 +44,7 @@
42
44
  constructor(...options) {
43
45
  for (let option of options) {
44
46
  if (typeof option == "string" || option instanceof String) {
45
- this.#options.url = "" + option;
46
- } else if (option instanceof _Client) {
47
- Object.assign(this.#options, option.#options);
47
+ this.clientOptions.url = "" + option;
48
48
  } else if (option instanceof Function) {
49
49
  this.#addMiddlewares([option]);
50
50
  } else if (option && typeof option == "object") {
@@ -52,27 +52,22 @@
52
52
  if (param == "middlewares") {
53
53
  this.#addMiddlewares(option[param]);
54
54
  } else if (typeof option[param] == "function") {
55
- this.#options[param] = option[param](this.#options[param], this.#options);
55
+ this.clientOptions[param] = option[param](this.clientOptions[param], this.clientOptions);
56
56
  } else {
57
- this.#options[param] = option[param];
57
+ this.clientOptions[param] = option[param];
58
58
  }
59
59
  }
60
60
  }
61
61
  }
62
- if (this.#options.verbs) {
63
- this.#verbs = this.#options.verbs;
64
- delete this.#options.verbs;
65
- }
66
- for (const verb of this.#verbs) {
62
+ for (const verb of this.clientOptions.verbs) {
67
63
  this[verb] = async function(...options2) {
68
64
  return this.fetch(request(
69
- this.#options,
65
+ this.clientOptions,
70
66
  ...options2,
71
67
  { method: verb.toUpperCase() }
72
68
  ));
73
69
  };
74
70
  }
75
- Object.freeze(this);
76
71
  }
77
72
  #addMiddlewares(middlewares) {
78
73
  if (typeof middlewares == "function") {
@@ -82,10 +77,10 @@
82
77
  if (index >= 0) {
83
78
  throw metroError("metro.client: middlewares must be a function or an array of functions " + metroURL + "client/invalid-middlewares/", middlewares[index]);
84
79
  }
85
- if (!Array.isArray(this.#options.middlewares)) {
86
- this.#options.middlewares = [];
80
+ if (!Array.isArray(this.clientOptions.middlewares)) {
81
+ this.clientOptions.middlewares = [];
87
82
  }
88
- this.#options.middlewares = this.#options.middlewares.concat(middlewares);
83
+ this.clientOptions.middlewares = this.clientOptions.middlewares.concat(middlewares);
89
84
  }
90
85
  /**
91
86
  * Mimics the standard browser fetch method, but uses any middleware installed through
@@ -112,8 +107,8 @@
112
107
  const res = await fetch(req2);
113
108
  return response(res);
114
109
  };
115
- let middlewares = [metrofetch].concat(this.#options?.middlewares?.slice() || []);
116
- options = Object.assign({}, this.#options, options);
110
+ let middlewares = [metrofetch].concat(this.clientOptions?.middlewares?.slice() || []);
111
+ options = Object.assign({}, this.clientOptions, options);
117
112
  let next;
118
113
  for (let middleware of middlewares) {
119
114
  next = /* @__PURE__ */ function(next2, middleware2) {
@@ -138,11 +133,11 @@
138
133
  return next(req);
139
134
  }
140
135
  with(...options) {
141
- return new _Client(this, ...options);
136
+ return new _Client(deepClone(this.clientOptions), ...options);
142
137
  }
143
138
  };
144
139
  function client(...options) {
145
- return new Client(...options);
140
+ return new Client(...deepClone(options));
146
141
  }
147
142
  function getRequestParams(req, current) {
148
143
  let params2 = current || {};
@@ -399,6 +394,7 @@
399
394
  Object.freeze(u);
400
395
  return new Proxy(u, {
401
396
  get(target, prop, receiver) {
397
+ let result;
402
398
  switch (prop) {
403
399
  case Symbol.metroProxy:
404
400
  return true;
@@ -417,6 +413,31 @@
417
413
  case "folderpath":
418
414
  return target.pathname.substring(0, target.pathname.lastIndexOf("\\") + 1);
419
415
  break;
416
+ case "authority":
417
+ result = target.username ?? "";
418
+ result += target.password ? ":" + target.password : "";
419
+ result += result ? "@" : "";
420
+ result += target.hostname;
421
+ result += target.port ? ":" + target.port : "";
422
+ result += "/";
423
+ result = target.protocol + "//" + result;
424
+ return result;
425
+ break;
426
+ case "origin":
427
+ result = target.protocol + "//" + target.hostname;
428
+ result += target.port ? ":" + target.port : "";
429
+ result += "/";
430
+ return result;
431
+ break;
432
+ case "fragment":
433
+ return target.hash.substring(1);
434
+ break;
435
+ case "scheme":
436
+ if (target.protocol) {
437
+ return target.protocol.substring(0, target.protocol.length - 1);
438
+ }
439
+ return "";
440
+ break;
420
441
  }
421
442
  if (target[prop] instanceof Function) {
422
443
  return target[prop].bind(target);
@@ -536,6 +557,23 @@
536
557
  };
537
558
  }
538
559
  };
560
+ function deepClone(object) {
561
+ if (Array.isArray(object)) {
562
+ return object.slice().map(deepClone);
563
+ }
564
+ if (object && typeof object === "object") {
565
+ if (object.__proto__.constructor == Object || !object.__proto__) {
566
+ let result = Object.assign({}, object);
567
+ Object.keys(result).forEach((key) => {
568
+ result[key] = deepClone(object[key]);
569
+ });
570
+ return result;
571
+ } else {
572
+ return object;
573
+ }
574
+ }
575
+ return object;
576
+ }
539
577
 
540
578
  // node_modules/@muze-nl/metro/src/mw/json.mjs
541
579
  function jsonmw(options) {
@@ -545,7 +583,7 @@
545
583
  replacer: null,
546
584
  space: ""
547
585
  }, options);
548
- return async (req, next) => {
586
+ return async function json(req, next) {
549
587
  if (!isJSON(req.headers.get("Accept"))) {
550
588
  req = req.with({
551
589
  headers: {
@@ -572,9 +610,9 @@
572
610
  let tempRes = res.clone();
573
611
  let body = await tempRes.text();
574
612
  try {
575
- let json = JSON.parse(body, options.reviver);
613
+ let json2 = JSON.parse(body, options.reviver);
576
614
  return res.with({
577
- body: json
615
+ body: json2
578
616
  });
579
617
  } catch (e) {
580
618
  }
@@ -588,8 +626,8 @@
588
626
  }
589
627
 
590
628
  // node_modules/@muze-nl/metro/src/mw/thrower.mjs
591
- function thrower(options) {
592
- return async (req, next) => {
629
+ function throwermw(options) {
630
+ return async function thrower(req, next) {
593
631
  let res = await next(req);
594
632
  if (!res.ok) {
595
633
  if (options && typeof options[res.status] == "function") {
@@ -608,7 +646,7 @@
608
646
  var metro = Object.assign({}, metro_exports, {
609
647
  mw: {
610
648
  jsonmw,
611
- thrower
649
+ thrower: throwermw
612
650
  }
613
651
  });
614
652
  if (!globalThis.metro) {
@@ -616,20 +654,6 @@
616
654
  }
617
655
  var everything_default = metro;
618
656
 
619
- // node_modules/@muze-nl/metro-oauth2/src/oauth2.mjs
620
- var oauth2_exports = {};
621
- __export(oauth2_exports, {
622
- base64url_encode: () => base64url_encode,
623
- createState: () => createState,
624
- default: () => oauth2mw,
625
- generateCodeChallenge: () => generateCodeChallenge,
626
- generateCodeVerifier: () => generateCodeVerifier,
627
- getExpires: () => getExpires,
628
- isAuthorized: () => isAuthorized,
629
- isExpired: () => isExpired,
630
- isRedirected: () => isRedirected
631
- });
632
-
633
657
  // node_modules/@muze-nl/assert/src/assert.mjs
634
658
  globalThis.assertEnabled = false;
635
659
  function assert(source, test) {
@@ -653,7 +677,7 @@
653
677
  function Required(pattern) {
654
678
  return function _Required(data, root, path) {
655
679
  if (data == null || typeof data == "undefined") {
656
- return error2("data is required", data, pattern || "any value", path);
680
+ return error("data is required", data, pattern || "any value", path);
657
681
  } else if (typeof pattern != "undefined") {
658
682
  return fails(data, pattern, root, path);
659
683
  } else {
@@ -664,7 +688,7 @@
664
688
  function Recommended(pattern) {
665
689
  return function _Recommended(data, root, path) {
666
690
  if (data == null || typeof data == "undefined") {
667
- console.warn("data does not contain recommended value", data, pattern, path);
691
+ warn("data does not contain recommended value", data, pattern, path);
668
692
  return false;
669
693
  } else {
670
694
  return fails(data, pattern, root, path);
@@ -678,17 +702,17 @@
678
702
  return false;
679
703
  }
680
704
  }
681
- return error2("data does not match oneOf patterns", data, patterns, path);
705
+ return error("data does not match oneOf patterns", data, patterns, path);
682
706
  };
683
707
  }
684
708
  function anyOf(...patterns) {
685
709
  return function _anyOf(data, root, path) {
686
710
  if (!Array.isArray(data)) {
687
- return error2("data is not an array", data, "anyOf", path);
711
+ return error("data is not an array", data, "anyOf", path);
688
712
  }
689
713
  for (let value of data) {
690
714
  if (oneOf(...patterns)(value)) {
691
- return error2("data does not match anyOf patterns", value, patterns, path);
715
+ return error("data does not match anyOf patterns", value, patterns, path);
692
716
  }
693
717
  }
694
718
  return false;
@@ -702,7 +726,7 @@
702
726
  }
703
727
  problems = problems.filter(Boolean);
704
728
  if (problems.length) {
705
- return error2("data does not match all given patterns", data, patterns, path, problems);
729
+ return error("data does not match all given patterns", data, patterns, path, problems);
706
730
  }
707
731
  };
708
732
  }
@@ -714,29 +738,29 @@
714
738
  let url2 = new URL(data);
715
739
  if (url2.href != data) {
716
740
  if (!(url2.href + "/" == data || url2.href == data + "/")) {
717
- return error2("data is not a valid url", data, "validURL", path);
741
+ return error("data is not a valid url", data, "validURL", path);
718
742
  }
719
743
  }
720
744
  } catch (e) {
721
- return error2("data is not a valid url", data, "validURL", path);
745
+ return error("data is not a valid url", data, "validURL", path);
722
746
  }
723
747
  }
724
748
  function validEmail(data, root, path) {
725
749
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data)) {
726
- return error2("data is not a valid email", data, "validEmail", path);
750
+ return error("data is not a valid email", data, "validEmail", path);
727
751
  }
728
752
  }
729
753
  function instanceOf(constructor) {
730
754
  return function _instanceOf(data, root, path) {
731
755
  if (!(data instanceof constructor)) {
732
- return error2("data is not an instanceof pattern", data, constructor, path);
756
+ return error("data is not an instanceof pattern", data, constructor, path);
733
757
  }
734
758
  };
735
759
  }
736
760
  function not(pattern) {
737
761
  return function _not(data, root, path) {
738
762
  if (!fails(data, pattern, root, path)) {
739
- return error2("data matches pattern, when required not to", data, pattern, path);
763
+ return error("data matches pattern, when required not to", data, pattern, path);
740
764
  }
741
765
  };
742
766
  }
@@ -747,29 +771,29 @@
747
771
  let problems = [];
748
772
  if (pattern === Boolean) {
749
773
  if (typeof data != "boolean" && !(data instanceof Boolean)) {
750
- problems.push(error2("data is not a boolean", data, pattern, path));
774
+ problems.push(error("data is not a boolean", data, pattern, path));
751
775
  }
752
776
  } else if (pattern === Number) {
753
777
  if (typeof data != "number" && !(data instanceof Number)) {
754
- problems.push(error2("data is not a number", data, pattern, path));
778
+ problems.push(error("data is not a number", data, pattern, path));
755
779
  }
756
780
  } else if (pattern === String) {
757
781
  if (typeof data != "string" && !(data instanceof String)) {
758
- problems.push(error2("data is not a string", data, pattern, path));
782
+ problems.push(error("data is not a string", data, pattern, path));
759
783
  }
760
784
  if (data == "") {
761
- problems.push(error2("data is an empty string, which is not allowed", data, pattern, path));
785
+ problems.push(error("data is an empty string, which is not allowed", data, pattern, path));
762
786
  }
763
787
  } else if (pattern instanceof RegExp) {
764
788
  if (Array.isArray(data)) {
765
789
  let index = data.findIndex((element, index2) => fails(element, pattern, root, path + "[" + index2 + "]"));
766
790
  if (index > -1) {
767
- problems.push(error2("data[" + index + "] does not match pattern", data[index], pattern, path + "[" + index + "]"));
791
+ problems.push(error("data[" + index + "] does not match pattern", data[index], pattern, path + "[" + index + "]"));
768
792
  }
769
793
  } else if (typeof data == "undefined") {
770
- problems.push(error2("data is undefined, should match pattern", data, pattern, path));
794
+ problems.push(error("data is undefined, should match pattern", data, pattern, path));
771
795
  } else if (!pattern.test(data)) {
772
- problems.push(error2("data does not match pattern", data, pattern, path));
796
+ problems.push(error("data does not match pattern", data, pattern, path));
773
797
  }
774
798
  } else if (pattern instanceof Function) {
775
799
  let problem = pattern(data, root, path);
@@ -782,7 +806,7 @@
782
806
  }
783
807
  } else if (Array.isArray(pattern)) {
784
808
  if (!Array.isArray(data)) {
785
- problems.push(error2("data is not an array", data, [], path));
809
+ problems.push(error("data is not an array", data, [], path));
786
810
  }
787
811
  for (let p of pattern) {
788
812
  for (let index of data.keys()) {
@@ -798,10 +822,10 @@
798
822
  if (Array.isArray(data)) {
799
823
  let index = data.findIndex((element, index2) => fails(element, pattern, root, path + "[" + index2 + "]"));
800
824
  if (index > -1) {
801
- problems.push(error2("data[" + index + "] does not match pattern", data[index], pattern, path + "[" + index + "]"));
825
+ problems.push(error("data[" + index + "] does not match pattern", data[index], pattern, path + "[" + index + "]"));
802
826
  }
803
827
  } else if (!data || typeof data != "object") {
804
- problems.push(error2("data is not an object, pattern is", data, pattern, path));
828
+ problems.push(error("data is not an object, pattern is", data, pattern, path));
805
829
  } else {
806
830
  if (data instanceof URLSearchParams) {
807
831
  data = Object.fromEntries(data);
@@ -812,8 +836,8 @@
812
836
  problems = problems.concat(result);
813
837
  }
814
838
  } else {
815
- for (const [wKey, wVal] of Object.entries(pattern)) {
816
- let result = fails(data[wKey], wVal, root, path + "." + wKey);
839
+ for (const [patternKey, subpattern] of Object.entries(pattern)) {
840
+ let result = fails(data[patternKey], subpattern, root, path + "." + patternKey);
817
841
  if (result) {
818
842
  problems = problems.concat(result);
819
843
  }
@@ -822,7 +846,7 @@
822
846
  }
823
847
  } else {
824
848
  if (pattern != data) {
825
- problems.push(error2("data and pattern are not equal", data, pattern, path));
849
+ problems.push(error("data and pattern are not equal", data, pattern, path));
826
850
  }
827
851
  }
828
852
  if (problems.length) {
@@ -830,18 +854,21 @@
830
854
  }
831
855
  return false;
832
856
  }
833
- function error2(message, found, expected, path, problems) {
857
+ function error(message, found, expected, path, problems) {
834
858
  let result = {
859
+ path,
835
860
  message,
836
861
  found,
837
- expected,
838
- path
862
+ expected
839
863
  };
840
864
  if (problems) {
841
865
  result.problems = problems;
842
866
  }
843
867
  return result;
844
868
  }
869
+ function warn(message, data, pattern, path) {
870
+ console.warn("\u{1F170}\uFE0F Assert: " + path, message, pattern, data);
871
+ }
845
872
 
846
873
  // node_modules/@muze-nl/metro-oauth2/src/tokenstore.mjs
847
874
  function tokenStore(site) {
@@ -893,9 +920,9 @@
893
920
  }
894
921
  };
895
922
  assert(options, {});
896
- const oauth22 = Object.assign({}, defaultOptions.oauth2_configuration, options?.oauth2_configuration);
923
+ const oauth2 = Object.assign({}, defaultOptions.oauth2_configuration, options?.oauth2_configuration);
897
924
  options = Object.assign({}, defaultOptions, options);
898
- options.oauth2_configuration = oauth22;
925
+ options.oauth2_configuration = oauth2;
899
926
  const store = tokenStore(options.site);
900
927
  if (!options.tokens) {
901
928
  options.tokens = store.tokens;
@@ -912,12 +939,12 @@
912
939
  redirect_uri: Required(validURL)
913
940
  }
914
941
  });
915
- for (let option in oauth22) {
942
+ for (let option in oauth2) {
916
943
  switch (option) {
917
944
  case "access_token":
918
945
  case "authorization_code":
919
946
  case "refresh_token":
920
- options.tokens.set(option, oauth22[option]);
947
+ options.tokens.set(option, oauth2[option]);
921
948
  break;
922
949
  }
923
950
  }
@@ -1012,7 +1039,7 @@
1012
1039
  }
1013
1040
  }
1014
1041
  async function fetchAccessToken() {
1015
- if (oauth22.grant_type === "authorization_code" && !options.tokens.has("authorization_code")) {
1042
+ if (oauth2.grant_type === "authorization_code" && !options.tokens.has("authorization_code")) {
1016
1043
  let authReqURL = await getAuthorizationCodeURL();
1017
1044
  if (!options.authorize_callback || typeof options.authorize_callback !== "function") {
1018
1045
  throw metroError("oauth2mw: oauth2 with grant_type:authorization_code requires a callback function in client options.authorize_callback");
@@ -1069,11 +1096,11 @@
1069
1096
  return data;
1070
1097
  }
1071
1098
  async function getAuthorizationCodeURL() {
1072
- if (!oauth22.authorization_endpoint) {
1099
+ if (!oauth2.authorization_endpoint) {
1073
1100
  throw metroError("oauth2mw: Missing options.oauth2_configuration.authorization_endpoint");
1074
1101
  }
1075
- let url2 = url(oauth22.authorization_endpoint, { hash: "" });
1076
- assert(oauth22, {
1102
+ let url2 = url(oauth2.authorization_endpoint, { hash: "" });
1103
+ assert(oauth2, {
1077
1104
  client_id: /.+/,
1078
1105
  redirect_uri: /.+/,
1079
1106
  scope: /.*/
@@ -1081,66 +1108,66 @@
1081
1108
  let search = {
1082
1109
  response_type: "code",
1083
1110
  // implicit flow uses 'token' here, but is not considered safe, so not supported
1084
- client_id: oauth22.client_id,
1085
- redirect_uri: oauth22.redirect_uri,
1086
- state: oauth22.state || createState(40)
1111
+ client_id: oauth2.client_id,
1112
+ redirect_uri: oauth2.redirect_uri,
1113
+ state: oauth2.state || createState(40)
1087
1114
  // OAuth2.1 RFC says optional, but its a good idea to always add/check it
1088
1115
  };
1089
- if (oauth22.response_type) {
1090
- search.response_type = oauth22.response_type;
1116
+ if (oauth2.response_type) {
1117
+ search.response_type = oauth2.response_type;
1091
1118
  }
1092
- if (oauth22.response_mode) {
1093
- search.response_mode = oauth22.response_mode;
1119
+ if (oauth2.response_mode) {
1120
+ search.response_mode = oauth2.response_mode;
1094
1121
  }
1095
1122
  options.state.set(search.state);
1096
- if (oauth22.code_verifier) {
1097
- options.tokens.set("code_verifier", oauth22.code_verifier);
1098
- search.code_challenge = await generateCodeChallenge(oauth22.code_verifier);
1099
- search.code_challenge_method = "S256";
1123
+ if (oauth2.client_secret) {
1124
+ search.client_secret = oauth2.client_secret;
1100
1125
  }
1101
- if (oauth22.client_secret) {
1102
- search.client_secret = oauth22.client_secret;
1126
+ if (oauth2.code_verifier) {
1127
+ options.tokens.set("code_verifier", oauth2.code_verifier);
1128
+ search.code_challenge = await generateCodeChallenge(oauth2.code_verifier);
1129
+ search.code_challenge_method = "S256";
1103
1130
  }
1104
- if (oauth22.scope) {
1105
- search.scope = oauth22.scope;
1131
+ if (oauth2.scope) {
1132
+ search.scope = oauth2.scope;
1106
1133
  }
1107
- if (oauth22.prompt) {
1108
- search.prompt = oauth22.prompt;
1134
+ if (oauth2.prompt) {
1135
+ search.prompt = oauth2.prompt;
1109
1136
  }
1110
1137
  return url(url2, { search });
1111
1138
  }
1112
1139
  function getAccessTokenRequest(grant_type = null) {
1113
- assert(oauth22, {
1140
+ assert(oauth2, {
1114
1141
  client_id: /.+/,
1115
1142
  redirect_uri: /.+/
1116
1143
  });
1117
- if (!oauth22.token_endpoint) {
1144
+ if (!oauth2.token_endpoint) {
1118
1145
  throw metroError("oauth2mw: Missing options.endpoints.token url");
1119
1146
  }
1120
- let url2 = url(oauth22.token_endpoint, { hash: "" });
1147
+ let url2 = url(oauth2.token_endpoint, { hash: "" });
1121
1148
  let params2 = {
1122
- grant_type: grant_type || oauth22.grant_type,
1123
- client_id: oauth22.client_id
1149
+ grant_type: grant_type || oauth2.grant_type,
1150
+ client_id: oauth2.client_id
1124
1151
  };
1125
1152
  const code_verifier = options.tokens.get("code_verifier");
1126
1153
  if (code_verifier) {
1127
1154
  params2.code_verifier = code_verifier;
1128
1155
  }
1129
- if (oauth22.client_secret) {
1130
- params2.client_secret = oauth22.client_secret;
1156
+ if (oauth2.client_secret) {
1157
+ params2.client_secret = oauth2.client_secret;
1131
1158
  }
1132
- if (oauth22.scope) {
1133
- params2.scope = oauth22.scope;
1159
+ if (oauth2.scope) {
1160
+ params2.scope = oauth2.scope;
1134
1161
  }
1135
- switch (oauth22.grant_type) {
1162
+ switch (oauth2.grant_type) {
1136
1163
  case "authorization_code":
1137
- params2.redirect_uri = oauth22.redirect_uri;
1164
+ params2.redirect_uri = oauth2.redirect_uri;
1138
1165
  params2.code = options.tokens.get("authorization_code");
1139
1166
  break;
1140
1167
  case "client_credentials":
1141
1168
  break;
1142
1169
  case "refresh_token":
1143
- params2.refresh_token = oauth22.refresh_token;
1170
+ params2.refresh_token = oauth2.refresh_token;
1144
1171
  break;
1145
1172
  default:
1146
1173
  throw new Error("Unknown grant_type: ".oauth2.grant_type);
@@ -1169,15 +1196,9 @@
1169
1196
  throw new TypeError("Unknown expires type " + duration);
1170
1197
  }
1171
1198
  function generateCodeVerifier(size = 64) {
1172
- size = Math.min(43, Math.max(128, size));
1173
- const allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
1174
- const random = new Uint8Array(size);
1175
- globalThis.crypto.getRandomValues(random);
1176
- const code_verifier = Array.from(random).map((b) => {
1177
- let c = allowed[b % allowed.length];
1178
- return c;
1179
- }).join("");
1180
- return code_verifier;
1199
+ const code_verifier = new Uint8Array(size);
1200
+ globalThis.crypto.getRandomValues(code_verifier);
1201
+ return base64url_encode(code_verifier);
1181
1202
  }
1182
1203
  async function generateCodeChallenge(code_verifier) {
1183
1204
  const encoder2 = new TextEncoder();
@@ -1213,280 +1234,17 @@
1213
1234
  }
1214
1235
  return true;
1215
1236
  }
1216
- function isAuthorized(tokens) {
1217
- if (typeof tokens == "string") {
1218
- tokens = tokenStore(tokens).tokens;
1219
- }
1220
- let accessToken = tokens.get("access_token");
1221
- if (accessToken && !isExpired(accessToken)) {
1222
- return true;
1223
- }
1224
- let refreshToken = tokens.get("refresh_token");
1225
- if (refreshToken) {
1226
- return true;
1227
- }
1228
- return false;
1229
- }
1230
-
1231
- // node_modules/@muze-nl/metro-oauth2/src/oauth2.mockserver.mjs
1232
- var oauth2_mockserver_exports = {};
1233
- __export(oauth2_mockserver_exports, {
1234
- default: () => oauth2mockserver
1235
- });
1236
- var baseResponse = {
1237
- status: 200,
1238
- statusText: "OK",
1239
- headers: {
1240
- "Content-Type": "application/json"
1241
- }
1242
- };
1243
- var badRequest = (error4) => {
1244
- return {
1245
- status: 400,
1246
- statusText: "Bad Request",
1247
- headers: {
1248
- "Content-Type": "application/json"
1249
- },
1250
- body: JSON.stringify({
1251
- error: "invalid_request",
1252
- error_description: error4
1253
- })
1254
- };
1255
- };
1256
- var error3;
1257
- var pkce = {};
1258
- function oauth2mockserver(options = {}) {
1259
- const defaultOptions = {
1260
- "PKCE": false,
1261
- "DPoP": false
1262
- };
1263
- options = Object.assign({}, defaultOptions, options);
1264
- return async (req, next) => {
1265
- let url2 = everything_default.url(req.url);
1266
- switch (url2.pathname) {
1267
- case "/authorize/":
1268
- if (error3 = fails(url2.searchParams, {
1269
- response_type: "code",
1270
- client_id: "mockClientId",
1271
- state: Optional(/.*/)
1272
- })) {
1273
- return everything_default.response(badRequest(error3));
1274
- }
1275
- if (url2.searchParams.has("code_challenge")) {
1276
- if (!url2.searchParams.has("code_challenge_method")) {
1277
- return everything_default.response(badRequest("missing code_challenge_method"));
1278
- }
1279
- pkce.code_challenge = url2.searchParams.get("code_challenge");
1280
- pkce.code_challenge_method = url2.searchParams.get("code_challenge_method");
1281
- }
1282
- return everything_default.response(baseResponse, {
1283
- body: JSON.stringify({
1284
- code: "mockAuthorizeToken",
1285
- state: url2.searchParams.get("state")
1286
- })
1287
- });
1288
- break;
1289
- case "/token/":
1290
- if (req.data instanceof URLSearchParams) {
1291
- let body = {};
1292
- req.data.forEach((value, key) => body[key] = value);
1293
- req = req.with({ body });
1294
- }
1295
- if (error3 = fails(req, {
1296
- method: "POST",
1297
- data: {
1298
- grant_type: oneOf("refresh_token", "authorization_code")
1299
- }
1300
- })) {
1301
- return everything_default.response(badRequest(error3));
1302
- }
1303
- switch (req.data.grant_type) {
1304
- case "refresh_token":
1305
- if (error3 = fails(req.data, oneOf({
1306
- refresh_token: "mockRefreshToken",
1307
- client_id: "mockClientId",
1308
- client_secret: "mockClientSecret"
1309
- }, {
1310
- refresh_token: "mockRefreshToken",
1311
- client_id: "mockClientId",
1312
- code_verifier: /.+/
1313
- }))) {
1314
- return everything_default.response(badRequest(error3));
1315
- }
1316
- break;
1317
- case "access_token":
1318
- if (error3 = fails(req.data, oneOf({
1319
- client_id: "mockClientId",
1320
- client_secret: "mockClientSecret"
1321
- }, {
1322
- client_id: "mockClientId",
1323
- code_challenge: /.*/,
1324
- //FIXME: check that this matches code_verifier
1325
- code_challenge_method: "S256"
1326
- }))) {
1327
- return everything_default.response(badRequest(error3));
1328
- }
1329
- break;
1330
- }
1331
- return everything_default.response(baseResponse, {
1332
- body: JSON.stringify({
1333
- access_token: "mockAccessToken",
1334
- token_type: "mockExample",
1335
- expires_in: 3600,
1336
- refresh_token: "mockRefreshToken",
1337
- example_parameter: "mockExampleValue"
1338
- })
1339
- });
1340
- break;
1341
- case "/protected/":
1342
- let auth = req.headers.get("Authorization");
1343
- let [type, token] = auth ? auth.split(" ") : [];
1344
- if (!token || token !== "mockAccessToken") {
1345
- return everything_default.response({
1346
- status: 401,
1347
- statusText: "Forbidden",
1348
- body: "401 Forbidden"
1349
- });
1350
- }
1351
- return everything_default.response(baseResponse, {
1352
- body: JSON.stringify({
1353
- result: "Success"
1354
- })
1355
- });
1356
- break;
1357
- case "/public/":
1358
- return everything_default.response(baseResponse, {
1359
- body: JSON.stringify({
1360
- result: "Success"
1361
- })
1362
- });
1363
- break;
1364
- default:
1365
- return everything_default.response({
1366
- status: 404,
1367
- statusText: "not found",
1368
- body: "404 Not Found " + url2
1369
- });
1370
- break;
1371
- }
1372
- };
1373
- }
1374
-
1375
- // node_modules/@muze-nl/metro-oauth2/src/oauth2.discovery.mjs
1376
- var oauth2_discovery_exports = {};
1377
- __export(oauth2_discovery_exports, {
1378
- default: () => makeClient
1379
- });
1380
- var validAlgorithms = [
1381
- "HS256",
1382
- "HS384",
1383
- "HS512",
1384
- "RS256",
1385
- "RS384",
1386
- "RS512",
1387
- "ES256",
1388
- "ES384",
1389
- "ES512"
1390
- ];
1391
- var validAuthMethods = [
1392
- "client_secret_post",
1393
- "client_secret_base",
1394
- "client_secret_jwt",
1395
- "private_key_jwt"
1396
- ];
1397
- var oauth_authorization_server_metadata = {
1398
- issuer: Required(validURL),
1399
- authorization_endpoint: Required(validURL),
1400
- token_endpoint: Required(validURL),
1401
- jwks_uri: Optional(validURL),
1402
- registration_endpoint: Optional(validURL),
1403
- scopes_supported: Recommended([]),
1404
- response_types_supported: Required(anyOf("code", "token")),
1405
- response_modes_supported: Optional([]),
1406
- grant_types_supported: Optional([]),
1407
- token_endpoint_auth_methods_supported: Optional([]),
1408
- token_endpoint_auth_signing_alg_values_supported: Optional([]),
1409
- service_documentation: Optional(validURL),
1410
- ui_locales_supported: Optional([]),
1411
- op_policy_uri: Optional(validURL),
1412
- op_tos_uri: Optional(validURL),
1413
- revocation_endpoint: Optional(validURL),
1414
- revocation_endpoint_auth_methods_supported: Optional(validAuthMethods),
1415
- revocation_endpoint_auth_signing_alg_values_supported: Optional(validAlgorithms),
1416
- introspection_endpoint: Optional(validURL),
1417
- introspection_endpoint_auth_methods_supported: Optional(validAuthMethods),
1418
- introspection_endpoint_auth_signing_alg_values_supported: Optional(validAlgorithms),
1419
- code_challendge_methods_supported: Optional([])
1420
- };
1421
- function makeClient(options = {}) {
1422
- const defaultOptions = {
1423
- client: everything_default.client()
1424
- };
1425
- options = Object.assign({}, defaultOptions, options);
1426
- assert(options, {
1427
- issuer: Required(validURL)
1428
- });
1429
- const oauth_authorization_server_configuration = fetchWellknownOauthAuthorizationServer(options.issuer);
1430
- let client2 = options.client.with(options.issuer);
1431
- }
1432
- async function fetchWellknownOauthAuthorizationServer(issuer, client2) {
1433
- let res = client2.get(everything_default.url(issuer, ".wellknown/oauth_authorization_server"));
1434
- if (res.ok) {
1435
- assert(res.headers.get("Content-Type"), /application\/json.*/);
1436
- let configuration = await res.json();
1437
- assert(configuration, oauth_authorization_server_metadata);
1438
- return configuration;
1439
- }
1440
- throw everything_default.metroError("metro.oidcmw: Error while fetching " + issuer + ".wellknown/oauth_authorization_server", res);
1441
- }
1442
-
1443
- // node_modules/@muze-nl/metro-oauth2/src/oauth2.popup.mjs
1444
- function handleRedirect() {
1445
- let params2 = new URLSearchParams(window.location.search);
1446
- if (!params2.has("code") && window.location.hash) {
1447
- let query = window.location.hash.substr(1);
1448
- params2 = new URLSearchParams("?" + query);
1449
- }
1450
- let parent = window.parent ? window.parent : window.opener;
1451
- if (params2.has("code")) {
1452
- parent.postMessage({
1453
- authorization_code: params2.get("code")
1454
- }, window.location.origin);
1455
- } else if (params2.has("error")) {
1456
- parent.postMessage({
1457
- error
1458
- }, window.location.origin);
1459
- } else {
1460
- parent.postMessage({
1461
- error: "Could not find an authorization_code"
1462
- }, window.location.origin);
1463
- }
1464
- }
1465
- function authorizePopup(authorizationCodeURL) {
1466
- return new Promise((resolve, reject) => {
1467
- addEventListener("message", (evt) => {
1468
- if (event.data.authorization_code) {
1469
- resolve(event.data.authorization_code);
1470
- } else if (event.data.error) {
1471
- reject(event.data.error);
1472
- } else {
1473
- reject("Unknown authorization error");
1474
- }
1475
- }, { once: true });
1476
- window.open(authorizationCodeURL);
1477
- });
1478
- }
1479
1237
 
1480
1238
  // node_modules/@muze-nl/metro-oauth2/src/keysstore.mjs
1481
1239
  function keysStore() {
1482
1240
  return new Promise((resolve, reject) => {
1483
1241
  const request2 = globalThis.indexedDB.open("metro", 1);
1484
1242
  request2.onupgradeneeded = () => request2.result.createObjectStore("keyPairs", { keyPath: "domain" });
1485
- request2.onerror = (event2) => {
1486
- reject(event2);
1243
+ request2.onerror = (event) => {
1244
+ reject(event);
1487
1245
  };
1488
- request2.onsuccess = (event2) => {
1489
- const db = event2.target.result;
1246
+ request2.onsuccess = (event) => {
1247
+ const db = event.target.result;
1490
1248
  resolve({
1491
1249
  set: function(value, key) {
1492
1250
  return new Promise((resolve2, reject2) => {
@@ -1779,33 +1537,18 @@
1779
1537
  };
1780
1538
  }
1781
1539
 
1782
- // node_modules/@muze-nl/metro-oauth2/src/browser.mjs
1783
- var oauth2 = Object.assign({}, oauth2_exports, {
1784
- oauth2mw,
1785
- mockserver: oauth2_mockserver_exports,
1786
- discover: oauth2_discovery_exports,
1787
- tokenstore: tokenStore,
1788
- dpopmw,
1789
- keysstore: keysStore,
1790
- authorizePopup,
1791
- popupHandleRedirect: handleRedirect
1792
- });
1793
- if (!globalThis.metro.oauth2) {
1794
- globalThis.metro.oauth2 = oauth2;
1795
- }
1796
-
1797
1540
  // src/oidc.util.mjs
1798
1541
  var MustHave = (...options) => (value, root) => {
1799
1542
  if (options.filter((o) => root.hasOwnKey(o)).length > 0) {
1800
1543
  return false;
1801
1544
  }
1802
- return error2("root data must have all of", root, options);
1545
+ return error("root data must have all of", root, options);
1803
1546
  };
1804
1547
  var MustInclude = (...options) => (value) => {
1805
1548
  if (Array.isArray(value) && options.filter((o) => !value.includes(o)).length == 0) {
1806
1549
  return false;
1807
1550
  } else {
1808
- return error2("data must be an array which includes", value, options);
1551
+ return error("data must be an array which includes", value, options);
1809
1552
  }
1810
1553
  };
1811
1554
  var validJWA = [
@@ -1819,7 +1562,7 @@
1819
1562
  "ES384",
1820
1563
  "ES512"
1821
1564
  ];
1822
- var validAuthMethods2 = [
1565
+ var validAuthMethods = [
1823
1566
  "client_secret_post",
1824
1567
  "client_secret_basic",
1825
1568
  "client_secret_jwt",
@@ -1833,7 +1576,7 @@
1833
1576
  issuer: Required(validURL)
1834
1577
  });
1835
1578
  const defaultOptions = {
1836
- client: everything_default.client().with(thrower()).with(jsonmw()),
1579
+ client: everything_default.client().with(throwermw()).with(jsonmw()),
1837
1580
  requireDynamicRegistration: false
1838
1581
  };
1839
1582
  options = Object.assign({}, defaultOptions, options);
@@ -1865,7 +1608,7 @@
1865
1608
  // not testing for 'none'
1866
1609
  request_object_encryption_alg_values_supported: Optional([]),
1867
1610
  request_object_encryption_enc_values_supported: Optional([]),
1868
- token_endpoint_auth_methods_supported: Optional(anyOf(...validAuthMethods2)),
1611
+ token_endpoint_auth_methods_supported: Optional(anyOf(...validAuthMethods)),
1869
1612
  token_endpoint_auth_signing_alg_values_supported: Optional(MustInclude("RS256"), not(MustInclude("none"))),
1870
1613
  display_values_supported: Optional(anyOf("page", "popup", "touch", "wap")),
1871
1614
  claim_types_supported: Optional(anyOf("normal", "aggregated", "distributed")),
@@ -1918,7 +1661,7 @@
1918
1661
  request_object_signing_alg: Optional(oneOf(...validJWA)),
1919
1662
  request_object_encryption_alg: Optional(oneOf(...validJWA)),
1920
1663
  request_object_encryption_enc: Optional(oneOf(...validJWA)),
1921
- token_endpoint_auth_method: Optional(oneOf(...validAuthMethods2)),
1664
+ token_endpoint_auth_method: Optional(oneOf(...validAuthMethods)),
1922
1665
  token_endpoint_auth_signing_alg: Optional(oneOf(...validJWA)),
1923
1666
  default_max_age: Optional(Number),
1924
1667
  require_auth_time: Optional(Boolean),
@@ -1932,7 +1675,7 @@
1932
1675
  client_info: openid_client_metadata
1933
1676
  });
1934
1677
  const defaultOptions = {
1935
- client: everything_default.client().with(thrower()).with(jsonmw())
1678
+ client: everything_default.client().with(throwermw()).with(jsonmw())
1936
1679
  };
1937
1680
  options = Object.assign({}, defaultOptions, options);
1938
1681
  let response2 = await options.client.post(options.registration_endpoint, {
@@ -2111,6 +1854,6 @@
2111
1854
  if (!globalThis.metro.oidc) {
2112
1855
  globalThis.metro.oidc = oidc;
2113
1856
  }
2114
- var browser_default2 = oidc;
1857
+ var browser_default = oidc;
2115
1858
  })();
2116
1859
  //# sourceMappingURL=browser.js.map