@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
@@ -1,2 +1,2 @@
1
- export declare const KEY_CURRENT_SESSION: string;
2
- export declare const KEY_CURRENT_URL: string;
1
+ export declare const KEY_CURRENT_SESSION = "solidClientAuthn:currentSession";
2
+ export declare const KEY_CURRENT_URL = "solidClientAuthn:currentUrl";
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ class ClientAuthentication extends solidClientAuthnCore.ClientAuthentication {
20
20
  await this.sessionInfoManager.clear(options.sessionId);
21
21
  const redirectUrl = (_a = options.redirectUrl) !== null && _a !== void 0 ? _a : oidcClientExt.removeOidcQueryParam(window.location.href);
22
22
  if (!solidClientAuthnCore.isValidRedirectUrl(redirectUrl)) {
23
- throw new Error(`${redirectUrl} is not a valid redirect URL, it is either a malformed IRI or it includes a hash fragment.`);
23
+ 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').`);
24
24
  }
25
25
  await this.loginHandler.handle({
26
26
  ...options,
@@ -83,6 +83,10 @@ class OidcLoginHandler {
83
83
  this.oidcHandler = oidcHandler;
84
84
  this.issuerConfigFetcher = issuerConfigFetcher;
85
85
  this.clientRegistrar = clientRegistrar;
86
+ this.storageUtility = storageUtility;
87
+ this.oidcHandler = oidcHandler;
88
+ this.issuerConfigFetcher = issuerConfigFetcher;
89
+ this.clientRegistrar = clientRegistrar;
86
90
  }
87
91
  async canHandle(options) {
88
92
  return hasIssuer(options) && hasRedirectUrl(options);
@@ -243,6 +247,7 @@ function processConfig(config) {
243
247
  class IssuerConfigFetcher {
244
248
  constructor(storageUtility) {
245
249
  this.storageUtility = storageUtility;
250
+ this.storageUtility = storageUtility;
246
251
  }
247
252
  static getLocalStorageKey(issuer) {
248
253
  return `issuerConfig:${issuer}`;
@@ -250,7 +255,7 @@ class IssuerConfigFetcher {
250
255
  async fetchConfig(issuer) {
251
256
  let issuerConfig;
252
257
  const openIdConfigUrl = new URL(WELL_KNOWN_OPENID_CONFIG, issuer.endsWith("/") ? issuer : `${issuer}/`).href;
253
- const issuerConfigRequestBody = await universalFetch.fetch(openIdConfigUrl);
258
+ const issuerConfigRequestBody = await universalFetch.fetch.call(globalThis, openIdConfigUrl);
254
259
  try {
255
260
  issuerConfig = processConfig(await issuerConfigRequestBody.json());
256
261
  }
@@ -268,32 +273,40 @@ async function clear(sessionId, storage) {
268
273
  }
269
274
  class SessionInfoManager extends solidClientAuthnCore.SessionInfoManagerBase {
270
275
  async get(sessionId) {
271
- var _a;
272
- const isLoggedIn = await this.storageUtility.getForUser(sessionId, "isLoggedIn", {
273
- secure: true,
274
- });
275
- const webId = await this.storageUtility.getForUser(sessionId, "webId", {
276
- secure: true,
277
- });
278
- const clientId = await this.storageUtility.getForUser(sessionId, "clientId", {
279
- secure: false,
280
- });
281
- const clientSecret = await this.storageUtility.getForUser(sessionId, "clientSecret", {
282
- secure: false,
283
- });
284
- const redirectUrl = await this.storageUtility.getForUser(sessionId, "redirectUrl", {
285
- secure: false,
286
- });
287
- const refreshToken = await this.storageUtility.getForUser(sessionId, "refreshToken", {
288
- secure: true,
289
- });
290
- const issuer = await this.storageUtility.getForUser(sessionId, "issuer", {
291
- secure: false,
292
- });
293
- const tokenType = (_a = (await this.storageUtility.getForUser(sessionId, "tokenType", {
294
- secure: false,
295
- }))) !== null && _a !== void 0 ? _a : "DPoP";
296
- if (!solidClientAuthnCore.isSupportedTokenType(tokenType)) {
276
+ const [isLoggedIn, webId, clientId, clientSecret, redirectUrl, refreshToken, issuer, tokenType,] = await Promise.all([
277
+ this.storageUtility.getForUser(sessionId, "isLoggedIn", {
278
+ secure: true,
279
+ }),
280
+ this.storageUtility.getForUser(sessionId, "webId", {
281
+ secure: true,
282
+ }),
283
+ this.storageUtility.getForUser(sessionId, "clientId", {
284
+ secure: false,
285
+ }),
286
+ this.storageUtility.getForUser(sessionId, "clientSecret", {
287
+ secure: false,
288
+ }),
289
+ this.storageUtility.getForUser(sessionId, "redirectUrl", {
290
+ secure: false,
291
+ }),
292
+ this.storageUtility.getForUser(sessionId, "refreshToken", {
293
+ secure: true,
294
+ }),
295
+ this.storageUtility.getForUser(sessionId, "issuer", {
296
+ secure: false,
297
+ }),
298
+ this.storageUtility.getForUser(sessionId, "tokenType", {
299
+ secure: false,
300
+ }),
301
+ ]);
302
+ if (typeof redirectUrl === "string" && !solidClientAuthnCore.isValidRedirectUrl(redirectUrl)) {
303
+ await Promise.all([
304
+ this.storageUtility.deleteAllUserData(sessionId, { secure: false }),
305
+ this.storageUtility.deleteAllUserData(sessionId, { secure: true }),
306
+ ]);
307
+ return undefined;
308
+ }
309
+ if (tokenType !== undefined && !solidClientAuthnCore.isSupportedTokenType(tokenType)) {
297
310
  throw new Error(`Tokens of type [${tokenType}] are not supported.`);
298
311
  }
299
312
  if (clientId === undefined &&
@@ -311,7 +324,7 @@ class SessionInfoManager extends solidClientAuthnCore.SessionInfoManagerBase {
311
324
  issuer,
312
325
  clientAppId: clientId,
313
326
  clientAppSecret: clientSecret,
314
- tokenType,
327
+ tokenType: tokenType !== null && tokenType !== void 0 ? tokenType : "DPoP",
315
328
  };
316
329
  }
317
330
  async clear(sessionId) {
@@ -334,6 +347,7 @@ class FallbackRedirectHandler {
334
347
  }
335
348
  }
336
349
 
350
+ const globalFetch = (...args) => universalFetch.fetch.call(globalThis, ...args);
337
351
  class AuthCodeRedirectHandler {
338
352
  constructor(storageUtility, sessionInfoManager, issuerConfigFetcher, clientRegistrar, tokerRefresher) {
339
353
  this.storageUtility = storageUtility;
@@ -341,6 +355,11 @@ class AuthCodeRedirectHandler {
341
355
  this.issuerConfigFetcher = issuerConfigFetcher;
342
356
  this.clientRegistrar = clientRegistrar;
343
357
  this.tokerRefresher = tokerRefresher;
358
+ this.storageUtility = storageUtility;
359
+ this.sessionInfoManager = sessionInfoManager;
360
+ this.issuerConfigFetcher = issuerConfigFetcher;
361
+ this.clientRegistrar = clientRegistrar;
362
+ this.tokerRefresher = tokerRefresher;
344
363
  }
345
364
  async canHandle(redirectUrl) {
346
365
  try {
@@ -395,7 +414,7 @@ class AuthCodeRedirectHandler {
395
414
  tokenRefresher: this.tokerRefresher,
396
415
  };
397
416
  }
398
- const authFetch = await solidClientAuthnCore.buildAuthenticatedFetch(universalFetch.fetch, tokens.accessToken, {
417
+ const authFetch = await solidClientAuthnCore.buildAuthenticatedFetch(globalFetch, tokens.accessToken, {
399
418
  dpopKey: tokens.dpopKey,
400
419
  refreshOptions,
401
420
  eventEmitter,
@@ -460,6 +479,7 @@ class Redirector {
460
479
  class ClientRegistrar {
461
480
  constructor(storageUtility) {
462
481
  this.storageUtility = storageUtility;
482
+ this.storageUtility = storageUtility;
463
483
  }
464
484
  async getClient(options, issuerConfig) {
465
485
  const [storedClientId, storedClientSecret,] = await Promise.all([
@@ -525,6 +545,9 @@ class TokenRefresher {
525
545
  this.storageUtility = storageUtility;
526
546
  this.issuerConfigFetcher = issuerConfigFetcher;
527
547
  this.clientRegistrar = clientRegistrar;
548
+ this.storageUtility = storageUtility;
549
+ this.issuerConfigFetcher = issuerConfigFetcher;
550
+ this.clientRegistrar = clientRegistrar;
528
551
  }
529
552
  async refresh(sessionId, refreshToken, dpopKey, eventEmitter) {
530
553
  const oidcContext = await solidClientAuthnCore.loadOidcContextFromStorage(sessionId, this.storageUtility, this.issuerConfigFetcher);