@inrupt/solid-client-authn-browser 1.17.0 → 1.17.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.
Files changed (38) hide show
  1. package/dist/constant.d.ts +2 -2
  2. package/dist/index.js +53 -30
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +53 -30
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/solid-client-authn.bundle.js +7 -7
  7. package/dist/solid-client-authn.bundle.js.map +1 -1
  8. package/package.json +6 -6
  9. package/rollup.config.mjs +1 -1
  10. package/src/ClientAuthentication.spec.ts +66 -38
  11. package/src/ClientAuthentication.ts +4 -4
  12. package/src/Session.spec.ts +44 -44
  13. package/src/Session.ts +24 -18
  14. package/src/__mocks__/ClientAuthentication.ts +2 -2
  15. package/src/defaultSession.ts +4 -3
  16. package/src/dependencies.ts +5 -5
  17. package/src/login/oidc/ClientRegistrar.spec.ts +22 -22
  18. package/src/login/oidc/ClientRegistrar.ts +4 -2
  19. package/src/login/oidc/IssuerConfigFetcher.spec.ts +25 -25
  20. package/src/login/oidc/IssuerConfigFetcher.ts +12 -7
  21. package/src/login/oidc/OidcLoginHandler.spec.ts +15 -15
  22. package/src/login/oidc/OidcLoginHandler.ts +14 -9
  23. package/src/login/oidc/Redirector.spec.ts +1 -1
  24. package/src/login/oidc/__mocks__/ClientRegistrar.ts +3 -3
  25. package/src/login/oidc/__mocks__/IssuerConfigFetcher.ts +3 -3
  26. package/src/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.spec.ts +42 -42
  27. package/src/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.ts +32 -19
  28. package/src/login/oidc/incomingRedirectHandler/ErrorOidcHandler.spec.ts +12 -12
  29. package/src/login/oidc/incomingRedirectHandler/ErrorOidcHandler.ts +2 -2
  30. package/src/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.spec.ts +7 -7
  31. package/src/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.ts +2 -2
  32. package/src/login/oidc/oidcHandlers/AuthorizationCodeWithPkceOidcHandler.spec.ts +17 -17
  33. package/src/login/oidc/refresh/TokenRefresher.spec.ts +14 -14
  34. package/src/login/oidc/refresh/TokenRefresher.ts +12 -8
  35. package/src/login/oidc/refresh/__mocks__/TokenRefresher.ts +1 -1
  36. package/src/sessionInfo/SessionInfoManager.spec.ts +37 -15
  37. package/src/sessionInfo/SessionInfoManager.ts +46 -50
  38. package/src/sessionInfo/__mocks__/SessionInfoManager.ts +3 -3
package/dist/index.mjs CHANGED
@@ -19,7 +19,7 @@ class ClientAuthentication extends ClientAuthentication$1 {
19
19
  await this.sessionInfoManager.clear(options.sessionId);
20
20
  const redirectUrl = (_a = options.redirectUrl) !== null && _a !== void 0 ? _a : removeOidcQueryParam(window.location.href);
21
21
  if (!isValidRedirectUrl(redirectUrl)) {
22
- throw new Error(`${redirectUrl} is not a valid redirect URL, it is either a malformed IRI or it includes a hash fragment.`);
22
+ throw new Error(`${redirectUrl} is not a valid redirect URL, it is either a malformed IRI, includes a hash fragment, or reserved query parameters ('code' or 'state').`);
23
23
  }
24
24
  await this.loginHandler.handle({
25
25
  ...options,
@@ -82,6 +82,10 @@ class OidcLoginHandler {
82
82
  this.oidcHandler = oidcHandler;
83
83
  this.issuerConfigFetcher = issuerConfigFetcher;
84
84
  this.clientRegistrar = clientRegistrar;
85
+ this.storageUtility = storageUtility;
86
+ this.oidcHandler = oidcHandler;
87
+ this.issuerConfigFetcher = issuerConfigFetcher;
88
+ this.clientRegistrar = clientRegistrar;
85
89
  }
86
90
  async canHandle(options) {
87
91
  return hasIssuer(options) && hasRedirectUrl(options);
@@ -242,6 +246,7 @@ function processConfig(config) {
242
246
  class IssuerConfigFetcher {
243
247
  constructor(storageUtility) {
244
248
  this.storageUtility = storageUtility;
249
+ this.storageUtility = storageUtility;
245
250
  }
246
251
  static getLocalStorageKey(issuer) {
247
252
  return `issuerConfig:${issuer}`;
@@ -249,7 +254,7 @@ class IssuerConfigFetcher {
249
254
  async fetchConfig(issuer) {
250
255
  let issuerConfig;
251
256
  const openIdConfigUrl = new URL(WELL_KNOWN_OPENID_CONFIG, issuer.endsWith("/") ? issuer : `${issuer}/`).href;
252
- const issuerConfigRequestBody = await fetch$1(openIdConfigUrl);
257
+ const issuerConfigRequestBody = await fetch$1.call(globalThis, openIdConfigUrl);
253
258
  try {
254
259
  issuerConfig = processConfig(await issuerConfigRequestBody.json());
255
260
  }
@@ -267,32 +272,40 @@ async function clear(sessionId, storage) {
267
272
  }
268
273
  class SessionInfoManager extends SessionInfoManagerBase {
269
274
  async get(sessionId) {
270
- var _a;
271
- const isLoggedIn = await this.storageUtility.getForUser(sessionId, "isLoggedIn", {
272
- secure: true,
273
- });
274
- const webId = await this.storageUtility.getForUser(sessionId, "webId", {
275
- secure: true,
276
- });
277
- const clientId = await this.storageUtility.getForUser(sessionId, "clientId", {
278
- secure: false,
279
- });
280
- const clientSecret = await this.storageUtility.getForUser(sessionId, "clientSecret", {
281
- secure: false,
282
- });
283
- const redirectUrl = await this.storageUtility.getForUser(sessionId, "redirectUrl", {
284
- secure: false,
285
- });
286
- const refreshToken = await this.storageUtility.getForUser(sessionId, "refreshToken", {
287
- secure: true,
288
- });
289
- const issuer = await this.storageUtility.getForUser(sessionId, "issuer", {
290
- secure: false,
291
- });
292
- const tokenType = (_a = (await this.storageUtility.getForUser(sessionId, "tokenType", {
293
- secure: false,
294
- }))) !== null && _a !== void 0 ? _a : "DPoP";
295
- if (!isSupportedTokenType(tokenType)) {
275
+ const [isLoggedIn, webId, clientId, clientSecret, redirectUrl, refreshToken, issuer, tokenType,] = await Promise.all([
276
+ this.storageUtility.getForUser(sessionId, "isLoggedIn", {
277
+ secure: true,
278
+ }),
279
+ this.storageUtility.getForUser(sessionId, "webId", {
280
+ secure: true,
281
+ }),
282
+ this.storageUtility.getForUser(sessionId, "clientId", {
283
+ secure: false,
284
+ }),
285
+ this.storageUtility.getForUser(sessionId, "clientSecret", {
286
+ secure: false,
287
+ }),
288
+ this.storageUtility.getForUser(sessionId, "redirectUrl", {
289
+ secure: false,
290
+ }),
291
+ this.storageUtility.getForUser(sessionId, "refreshToken", {
292
+ secure: true,
293
+ }),
294
+ this.storageUtility.getForUser(sessionId, "issuer", {
295
+ secure: false,
296
+ }),
297
+ this.storageUtility.getForUser(sessionId, "tokenType", {
298
+ secure: false,
299
+ }),
300
+ ]);
301
+ if (typeof redirectUrl === "string" && !isValidRedirectUrl(redirectUrl)) {
302
+ await Promise.all([
303
+ this.storageUtility.deleteAllUserData(sessionId, { secure: false }),
304
+ this.storageUtility.deleteAllUserData(sessionId, { secure: true }),
305
+ ]);
306
+ return undefined;
307
+ }
308
+ if (tokenType !== undefined && !isSupportedTokenType(tokenType)) {
296
309
  throw new Error(`Tokens of type [${tokenType}] are not supported.`);
297
310
  }
298
311
  if (clientId === undefined &&
@@ -310,7 +323,7 @@ class SessionInfoManager extends SessionInfoManagerBase {
310
323
  issuer,
311
324
  clientAppId: clientId,
312
325
  clientAppSecret: clientSecret,
313
- tokenType,
326
+ tokenType: tokenType !== null && tokenType !== void 0 ? tokenType : "DPoP",
314
327
  };
315
328
  }
316
329
  async clear(sessionId) {
@@ -333,6 +346,7 @@ class FallbackRedirectHandler {
333
346
  }
334
347
  }
335
348
 
349
+ const globalFetch = (...args) => fetch$1.call(globalThis, ...args);
336
350
  class AuthCodeRedirectHandler {
337
351
  constructor(storageUtility, sessionInfoManager, issuerConfigFetcher, clientRegistrar, tokerRefresher) {
338
352
  this.storageUtility = storageUtility;
@@ -340,6 +354,11 @@ class AuthCodeRedirectHandler {
340
354
  this.issuerConfigFetcher = issuerConfigFetcher;
341
355
  this.clientRegistrar = clientRegistrar;
342
356
  this.tokerRefresher = tokerRefresher;
357
+ this.storageUtility = storageUtility;
358
+ this.sessionInfoManager = sessionInfoManager;
359
+ this.issuerConfigFetcher = issuerConfigFetcher;
360
+ this.clientRegistrar = clientRegistrar;
361
+ this.tokerRefresher = tokerRefresher;
343
362
  }
344
363
  async canHandle(redirectUrl) {
345
364
  try {
@@ -394,7 +413,7 @@ class AuthCodeRedirectHandler {
394
413
  tokenRefresher: this.tokerRefresher,
395
414
  };
396
415
  }
397
- const authFetch = await buildAuthenticatedFetch(fetch$1, tokens.accessToken, {
416
+ const authFetch = await buildAuthenticatedFetch(globalFetch, tokens.accessToken, {
398
417
  dpopKey: tokens.dpopKey,
399
418
  refreshOptions,
400
419
  eventEmitter,
@@ -459,6 +478,7 @@ class Redirector {
459
478
  class ClientRegistrar {
460
479
  constructor(storageUtility) {
461
480
  this.storageUtility = storageUtility;
481
+ this.storageUtility = storageUtility;
462
482
  }
463
483
  async getClient(options, issuerConfig) {
464
484
  const [storedClientId, storedClientSecret,] = await Promise.all([
@@ -524,6 +544,9 @@ class TokenRefresher {
524
544
  this.storageUtility = storageUtility;
525
545
  this.issuerConfigFetcher = issuerConfigFetcher;
526
546
  this.clientRegistrar = clientRegistrar;
547
+ this.storageUtility = storageUtility;
548
+ this.issuerConfigFetcher = issuerConfigFetcher;
549
+ this.clientRegistrar = clientRegistrar;
527
550
  }
528
551
  async refresh(sessionId, refreshToken, dpopKey, eventEmitter) {
529
552
  const oidcContext = await loadOidcContextFromStorage(sessionId, this.storageUtility, this.issuerConfigFetcher);