@muze-nl/metro-oidc 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -1093,12 +1093,12 @@
1093
1093
  search.response_mode = oauth22.response_mode;
1094
1094
  }
1095
1095
  options.state.set(search.state);
1096
- if (oauth22.client_secret) {
1097
- search.client_secret = oauth22.client_secret;
1098
- }
1099
1096
  if (oauth22.code_verifier) {
1097
+ options.tokens.set("code_verifier", oauth22.code_verifier);
1100
1098
  search.code_challenge = await generateCodeChallenge(oauth22.code_verifier);
1101
1099
  search.code_challenge_method = "S256";
1100
+ } else if (oauth22.client_secret) {
1101
+ search.client_secret = oauth22.client_secret;
1102
1102
  }
1103
1103
  if (oauth22.scope) {
1104
1104
  search.scope = oauth22.scope;
@@ -1121,10 +1121,10 @@
1121
1121
  grant_type: grant_type || oauth22.grant_type,
1122
1122
  client_id: oauth22.client_id
1123
1123
  };
1124
- if (oauth22.code_verifier) {
1125
- params2.code_verifier = oauth22.code_verifier;
1126
- }
1127
- if (oauth22.client_secret) {
1124
+ const code_verifier = options.tokens.get("code_verifier");
1125
+ if (code_verifier) {
1126
+ params2.code_verifier = code_verifier;
1127
+ } else if (oauth22.client_secret) {
1128
1128
  params2.client_secret = oauth22.client_secret;
1129
1129
  }
1130
1130
  if (oauth22.scope) {
@@ -1167,9 +1167,15 @@
1167
1167
  throw new TypeError("Unknown expires type " + duration);
1168
1168
  }
1169
1169
  function generateCodeVerifier(size = 64) {
1170
- const code_verifier = new Uint8Array(size);
1171
- globalThis.crypto.getRandomValues(code_verifier);
1172
- return base64url_encode(code_verifier);
1170
+ size = Math.min(43, Math.max(128, size));
1171
+ const allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
1172
+ const random = new Uint8Array(size);
1173
+ globalThis.crypto.getRandomValues(random);
1174
+ const code_verifier = Array.from(random).map((b) => {
1175
+ let c = allowed[b % allowed.length];
1176
+ return c;
1177
+ }).join("");
1178
+ return code_verifier;
1173
1179
  }
1174
1180
  async function generateCodeChallenge(code_verifier) {
1175
1181
  const encoder2 = new TextEncoder();
@@ -2042,6 +2048,12 @@
2042
2048
  }
2043
2049
  //...
2044
2050
  );
2051
+ const pkceSupported = options.openid_configuration.code_challenge_methods_supported.length;
2052
+ if (pkceSupported) {
2053
+ delete oauth2Options.oauth2_configuration.client_secret;
2054
+ } else {
2055
+ oauth2Options.oauth2_configuration.code_verifier = false;
2056
+ }
2045
2057
  const storeIdToken = async (req2, next2) => {
2046
2058
  const res2 = await next2(req2);
2047
2059
  const contentType = res2.headers.get("content-type");