@inrupt/solid-client-authn-browser 1.17.4 → 2.0.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.
Files changed (45) hide show
  1. package/dist/ClientAuthentication.d.ts +1 -0
  2. package/dist/Session.d.ts +4 -67
  3. package/dist/defaultSession.d.ts +0 -28
  4. package/dist/dependencies.d.ts +1 -2
  5. package/dist/index.d.ts +2 -3
  6. package/dist/index.js +16 -124
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +9 -113
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/login/oidc/__mocks__/IOidcOptions.d.ts +2 -0
  11. package/dist/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.d.ts +4 -0
  12. package/dist/solid-client-authn.bundle.js +19 -19
  13. package/dist/solid-client-authn.bundle.js.map +1 -1
  14. package/package.json +6 -7
  15. package/rollup.config.mjs +28 -14
  16. package/src/ClientAuthentication.spec.ts +1 -12
  17. package/src/Session.spec.ts +11 -178
  18. package/src/Session.ts +6 -98
  19. package/src/defaultSession.spec.ts +0 -18
  20. package/src/defaultSession.ts +0 -40
  21. package/src/dependencies.ts +1 -2
  22. package/src/index.spec.ts +1 -2
  23. package/src/index.ts +9 -3
  24. package/src/login/oidc/ClientRegistrar.spec.ts +8 -9
  25. package/src/login/oidc/IssuerConfigFetcher.spec.ts +17 -32
  26. package/src/login/oidc/IssuerConfigFetcher.ts +1 -5
  27. package/src/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.spec.ts +9 -29
  28. package/src/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.ts +6 -19
  29. package/src/login/oidc/incomingRedirectHandler/ErrorOidcHandler.spec.ts +0 -11
  30. package/src/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.spec.ts +1 -12
  31. package/.prettierignore +0 -3
  32. package/sampleFlows/SolidAuthClientArchitecture.png +0 -0
  33. package/sampleFlows/authorization-code-with-pkce.png +0 -0
  34. package/sampleFlows/authorization-code-with-pkce.seqdiag +0 -46
  35. package/sampleFlows/authorization-code.png +0 -0
  36. package/sampleFlows/authorization-code.seqdiag +0 -50
  37. package/sampleFlows/client-credentials.png +0 -0
  38. package/sampleFlows/client-credentials.seqdiag +0 -38
  39. package/sampleFlows/legacy-implicit-flow.png +0 -0
  40. package/sampleFlows/legacy-implicit-flow.seqdiag +0 -43
  41. package/sampleFlows/self-signed.png +0 -0
  42. package/sampleFlows/self-signed.seqdiag +0 -49
  43. package/sampleFlows/signatory-access-control.seqdiag +0 -36
  44. package/sampleFlows/signatory-access-control.svg +0 -1
  45. package/sonar-project.properties +0 -15
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  /**
2
3
  * @hidden
3
4
  * @packageDocumentation
package/dist/Session.d.ts CHANGED
@@ -1,10 +1,7 @@
1
- /// <reference types="node" />
2
1
  /**
3
2
  * @hidden
4
3
  */
5
4
  import type { ILoginInputOptions, ISessionInfo, IStorage, IHasSessionEventListener, ISessionEventListener, ILogoutOptions } from "@inrupt/solid-client-authn-core";
6
- import type { fetch } from "@inrupt/universal-fetch";
7
- import EventEmitter from "events";
8
5
  import type ClientAuthentication from "./ClientAuthentication";
9
6
  export interface ISessionOptions {
10
7
  /**
@@ -33,28 +30,10 @@ export interface IHandleIncomingRedirectOptions {
33
30
  * If your app's access has not expired yet and re-activation completed
34
31
  * successfully, a `sessionRestore` event will be fired with the URL the user
35
32
  * was at before they were redirected to their Solid Identity Provider.
36
- * {@see onSessionRestore}
33
+ * See {@link ISessionEventListener}: a callback can be registered to
34
+ * `session.events.on(EVENTS.SESSION_RESTORED, callback)`.
37
35
  */
38
36
  restorePreviousSession?: boolean;
39
- /**
40
- * Inrupt's Enterprise Solid Server can set a cookie to allow the browser to
41
- * access private resources on a Pod. In order to mitigate the logout-on-refresh
42
- * issue on the short term, the server also implemented a session endpoint
43
- * enabling the client app to know whether the cookie is set. When a user
44
- * logs in to a server that has that capability enabled, applications that set
45
- * this option to `true` will be able to make use of it.
46
- *
47
- * If your app supports the newest session restore approach, and `restorePreviousSession`
48
- * is set to true, this option is automatically set to false, but your app will
49
- * not be logged out when reloaded.
50
- *
51
- * `useEssSession` defaults to false and will be removed in the future; to
52
- * preserve sessions across page reloads, use of `restorePreviousSession` is
53
- * recommended.
54
- *
55
- * @deprecated unreleased
56
- */
57
- useEssSession?: boolean;
58
37
  /**
59
38
  * The URL of the page handling the redirect, including the query
60
39
  * parameters — these contain the information to process the login.
@@ -67,7 +46,7 @@ export declare function silentlyAuthenticate(sessionId: string, clientAuthn: Cli
67
46
  /**
68
47
  * A {@link Session} object represents a user's session on an application. The session holds state, as it stores information enabling acces to private resources after login for instance.
69
48
  */
70
- export declare class Session extends EventEmitter implements IHasSessionEventListener {
49
+ export declare class Session implements IHasSessionEventListener {
71
50
  /**
72
51
  * Information regarding the current session.
73
52
  */
@@ -160,50 +139,8 @@ export declare class Session extends EventEmitter implements IHasSessionEventLis
160
139
  * Completes the login process by processing the information provided by the
161
140
  * Solid identity provider through redirect.
162
141
  *
163
- * @param options See {@see IHandleIncomingRedirectOptions}.
142
+ * @param options See {@link IHandleIncomingRedirectOptions}.
164
143
  */
165
144
  handleIncomingRedirect: (inputOptions?: string | IHandleIncomingRedirectOptions) => Promise<ISessionInfo | undefined>;
166
- /**
167
- * Register a callback function to be called when a user completes login.
168
- *
169
- * The callback is called when {@link handleIncomingRedirect} completes successfully.
170
- *
171
- * @param callback The function called when a user completes login.
172
- * @deprecated Prefer session.events.on(EVENTS.LOGIN, callback)
173
- */
174
- onLogin(callback: () => unknown): void;
175
- /**
176
- * Register a callback function to be called when a user logs out:
177
- *
178
- * @param callback The function called when a user completes logout.
179
- * @deprecated Prefer session.events.on(EVENTS.LOGOUT, callback)
180
- */
181
- onLogout(callback: () => unknown): void;
182
- /**
183
- * Register a callback function to be called when a user logs out:
184
- *
185
- * @param callback The function called when an error occurs.
186
- * @since 1.11.0
187
- * @deprecated Prefer session.events.on(EVENTS.ERROR, callback)
188
- */
189
- onError(callback: (error: string | null, errorDescription?: string | null) => unknown): void;
190
- /**
191
- * Register a callback function to be called when a session is restored.
192
- *
193
- * Note: the callback will be called with the saved value of the 'current URL'
194
- * at the time the session was restored.
195
- *
196
- * @param callback The function called when a user's already logged-in session is restored, e.g., after a silent authentication is completed after a page refresh.
197
- * @deprecated Prefer session.events.on(EVENTS.SESSION_RESTORED, callback)
198
- */
199
- onSessionRestore(callback: (currentUrl: string) => unknown): void;
200
- /**
201
- * Register a callback that runs when the session expires and can no longer
202
- * make authenticated requests, but following a user logout.
203
- * @param callback The function that runs on session expiration.
204
- * @since 1.11.0
205
- * @deprecated Prefer session.events.on(EVENTS.SESSION_EXPIRED, callback)
206
- */
207
- onSessionExpiration(callback: () => unknown): void;
208
145
  private setSessionInfo;
209
146
  }
@@ -44,34 +44,6 @@ export declare const logout: Session["logout"];
44
44
  * @since 1.3.0
45
45
  */
46
46
  export declare const handleIncomingRedirect: Session["handleIncomingRedirect"];
47
- /**
48
- * Register a callback function to be called when a user completes login.
49
- *
50
- * The callback is called when {@link handleIncomingRedirect} completes successfully.
51
- * @since 1.3.0
52
- *
53
- * @param callback The function called when a user completes login.
54
- * @deprecated Prefer events.on(EVENTS.LOGIN, callback)
55
-
56
- */
57
- export declare const onLogin: Session["onLogin"];
58
- /**
59
- * Register a callback function to be called when a user logs out:
60
- *
61
- * @param callback The function called when a user completes logout.
62
- * @since 1.3.0
63
- * @deprecated Prefer events.on(EVENTS.LOGOUT, callback)
64
- *
65
- */
66
- export declare const onLogout: Session["onLogout"];
67
- /**
68
- * Register a callback function to be called when a session is restored:
69
- *
70
- * @param callback The function called when a session is restored.
71
- * @since 1.3.0
72
- * @deprecated Prefer events.on(EVENTS.SESSION_RESTORED, callback)
73
- */
74
- export declare const onSessionRestore: Session["onSessionRestore"];
75
47
  /**
76
48
  * {@link SessionEventEmitter} instance to subscribe to events by the default session.
77
49
  *
@@ -8,9 +8,8 @@
8
8
  import type { IStorage } from "@inrupt/solid-client-authn-core";
9
9
  import ClientAuthentication from "./ClientAuthentication";
10
10
  /**
11
- *
12
11
  * @param dependencies
13
- * @deprecated This function will be removed from the external API in an upcoming release.
12
+ * @hidden
14
13
  */
15
14
  export declare function getClientAuthenticationWithDependencies(dependencies: {
16
15
  secureStorage?: IStorage;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { Session, ISessionOptions } from "./Session";
2
- export { getClientAuthenticationWithDependencies } from "./dependencies";
1
+ export { Session, ISessionOptions, IHandleIncomingRedirectOptions, } from "./Session";
3
2
  export * from "./defaultSession";
4
- export { ILoginInputOptions, ISessionInfo, IStorage, NotImplementedError, ConfigurationError, InMemoryStorage, EVENTS, } from "@inrupt/solid-client-authn-core";
3
+ export { ILoginInputOptions, ISessionInfo, IStorage, NotImplementedError, ConfigurationError, InMemoryStorage, IHasSessionEventListener, ISessionEventListener, IEndSessionOptions, ILogoutOptions, EVENTS, } from "@inrupt/solid-client-authn-core";
package/dist/index.js CHANGED
@@ -4,7 +4,6 @@ var solidClientAuthnCore = require('@inrupt/solid-client-authn-core');
4
4
  var uuid = require('uuid');
5
5
  var EventEmitter = require('events');
6
6
  var oidcClientExt = require('@inrupt/oidc-client-ext');
7
- var universalFetch = require('@inrupt/universal-fetch');
8
7
 
9
8
  //
10
9
  // Copyright Inrupt Inc.
@@ -445,7 +444,7 @@ class IssuerConfigFetcher {
445
444
  // Make sure to append a slash at issuer URL, so that the .well-known URL
446
445
  // includes the full issuer path. See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig.
447
446
  issuer.endsWith("/") ? issuer : `${issuer}/`).href;
448
- const issuerConfigRequestBody = await universalFetch.fetch.call(globalThis, openIdConfigUrl);
447
+ const issuerConfigRequestBody = await fetch(openIdConfigUrl);
449
448
  // Check the validity of the fetched config
450
449
  try {
451
450
  issuerConfig = processConfig(await issuerConfigRequestBody.json());
@@ -627,14 +626,6 @@ class FallbackRedirectHandler {
627
626
  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
628
627
  // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
629
628
  //
630
- /**
631
- * @hidden
632
- * @packageDocumentation
633
- */
634
- // FIXME: The following doesn't work in the browser, it results in all the fetches
635
- // being unauthenticated. This should be looked into when migrating to universal-fetch.
636
- // import { fetch } from "cross-fetch";
637
- const globalFetch = (...args) => universalFetch.fetch.call(globalThis, ...args);
638
629
  /**
639
630
  * @hidden
640
631
  */
@@ -709,7 +700,7 @@ class AuthCodeRedirectHandler {
709
700
  tokenRefresher: this.tokerRefresher,
710
701
  };
711
702
  }
712
- const authFetch = await solidClientAuthnCore.buildAuthenticatedFetch(globalFetch, tokens.accessToken, {
703
+ const authFetch = await solidClientAuthnCore.buildAuthenticatedFetch(tokens.accessToken, {
713
704
  dpopKey: tokens.dpopKey,
714
705
  refreshOptions,
715
706
  eventEmitter,
@@ -1043,9 +1034,8 @@ class TokenRefresher {
1043
1034
  // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1044
1035
  //
1045
1036
  /**
1046
- *
1047
1037
  * @param dependencies
1048
- * @deprecated This function will be removed from the external API in an upcoming release.
1038
+ * @hidden
1049
1039
  */
1050
1040
  function getClientAuthenticationWithDependencies(dependencies) {
1051
1041
  const inMemoryStorage = new solidClientAuthnCore.InMemoryStorage();
@@ -1140,7 +1130,7 @@ function isLoggedIn(sessionInfo) {
1140
1130
  /**
1141
1131
  * A {@link Session} object represents a user's session on an application. The session holds state, as it stores information enabling acces to private resources after login for instance.
1142
1132
  */
1143
- class Session extends EventEmitter {
1133
+ class Session {
1144
1134
  /**
1145
1135
  * Session object constructor. Typically called as follows:
1146
1136
  *
@@ -1157,7 +1147,6 @@ class Session extends EventEmitter {
1157
1147
  *
1158
1148
  */
1159
1149
  constructor(sessionOptions = {}, sessionId = undefined) {
1160
- super();
1161
1150
  this.tokenRequestInProgress = false;
1162
1151
  /**
1163
1152
  * Triggers the login process. Note that this method will redirect the user away from your app.
@@ -1248,7 +1237,7 @@ class Session extends EventEmitter {
1248
1237
  * Completes the login process by processing the information provided by the
1249
1238
  * Solid identity provider through redirect.
1250
1239
  *
1251
- * @param options See {@see IHandleIncomingRedirectOptions}.
1240
+ * @param options See {@link IHandleIncomingRedirectOptions}.
1252
1241
  */
1253
1242
  this.handleIncomingRedirect = async (inputOptions = {}) => {
1254
1243
  var _a;
@@ -1301,11 +1290,7 @@ class Session extends EventEmitter {
1301
1290
  this.tokenRequestInProgress = false;
1302
1291
  return sessionInfo;
1303
1292
  };
1304
- // Until Session no longer implements EventEmitter, this.events is just a proxy
1305
- // to this (with some interface filtering). When we make the breaking change,
1306
- // this.events will be a regular EventEmitter (implementing ISessionEventEmitter):
1307
- // this.events = new EventEmitter();
1308
- this.events = new Proxy(this, solidClientAuthnCore.buildProxyHandler(Session.prototype, "events only implements ISessionEventListener"));
1293
+ this.events = new EventEmitter();
1309
1294
  if (sessionOptions.clientAuthentication) {
1310
1295
  this.clientAuthentication = sessionOptions.clientAuthentication;
1311
1296
  }
@@ -1339,58 +1324,6 @@ class Session extends EventEmitter {
1339
1324
  this.events.on(solidClientAuthnCore.EVENTS.SESSION_EXPIRED, () => this.internalLogout(false));
1340
1325
  this.events.on(solidClientAuthnCore.EVENTS.ERROR, () => this.internalLogout(false));
1341
1326
  }
1342
- /**
1343
- * Register a callback function to be called when a user completes login.
1344
- *
1345
- * The callback is called when {@link handleIncomingRedirect} completes successfully.
1346
- *
1347
- * @param callback The function called when a user completes login.
1348
- * @deprecated Prefer session.events.on(EVENTS.LOGIN, callback)
1349
- */
1350
- onLogin(callback) {
1351
- this.events.on(solidClientAuthnCore.EVENTS.LOGIN, callback);
1352
- }
1353
- /**
1354
- * Register a callback function to be called when a user logs out:
1355
- *
1356
- * @param callback The function called when a user completes logout.
1357
- * @deprecated Prefer session.events.on(EVENTS.LOGOUT, callback)
1358
- */
1359
- onLogout(callback) {
1360
- this.events.on(solidClientAuthnCore.EVENTS.LOGOUT, callback);
1361
- }
1362
- /**
1363
- * Register a callback function to be called when a user logs out:
1364
- *
1365
- * @param callback The function called when an error occurs.
1366
- * @since 1.11.0
1367
- * @deprecated Prefer session.events.on(EVENTS.ERROR, callback)
1368
- */
1369
- onError(callback) {
1370
- this.events.on(solidClientAuthnCore.EVENTS.ERROR, callback);
1371
- }
1372
- /**
1373
- * Register a callback function to be called when a session is restored.
1374
- *
1375
- * Note: the callback will be called with the saved value of the 'current URL'
1376
- * at the time the session was restored.
1377
- *
1378
- * @param callback The function called when a user's already logged-in session is restored, e.g., after a silent authentication is completed after a page refresh.
1379
- * @deprecated Prefer session.events.on(EVENTS.SESSION_RESTORED, callback)
1380
- */
1381
- onSessionRestore(callback) {
1382
- this.events.on(solidClientAuthnCore.EVENTS.SESSION_RESTORED, callback);
1383
- }
1384
- /**
1385
- * Register a callback that runs when the session expires and can no longer
1386
- * make authenticated requests, but following a user logout.
1387
- * @param callback The function that runs on session expiration.
1388
- * @since 1.11.0
1389
- * @deprecated Prefer session.events.on(EVENTS.SESSION_EXPIRED, callback)
1390
- */
1391
- onSessionExpiration(callback) {
1392
- this.events.on(solidClientAuthnCore.EVENTS.SESSION_EXPIRED, callback);
1393
- }
1394
1327
  setSessionInfo(sessionInfo) {
1395
1328
  this.info.isLoggedIn = sessionInfo.isLoggedIn;
1396
1329
  this.info.webId = sessionInfo.webId;
@@ -1448,7 +1381,7 @@ function getDefaultSession() {
1448
1381
  * @since 1.3.0
1449
1382
  */
1450
1383
  /* eslint-disable-next-line no-shadow */
1451
- const fetch = (...args) => {
1384
+ const fetch$1 = (...args) => {
1452
1385
  const session = getDefaultSession();
1453
1386
  return session.fetch(...args);
1454
1387
  };
@@ -1486,43 +1419,6 @@ const handleIncomingRedirect = (...args) => {
1486
1419
  const session = getDefaultSession();
1487
1420
  return session.handleIncomingRedirect(...args);
1488
1421
  };
1489
- /**
1490
- * Register a callback function to be called when a user completes login.
1491
- *
1492
- * The callback is called when {@link handleIncomingRedirect} completes successfully.
1493
- * @since 1.3.0
1494
- *
1495
- * @param callback The function called when a user completes login.
1496
- * @deprecated Prefer events.on(EVENTS.LOGIN, callback)
1497
-
1498
- */
1499
- const onLogin = (...args) => {
1500
- const session = getDefaultSession();
1501
- return session.onLogin(...args);
1502
- };
1503
- /**
1504
- * Register a callback function to be called when a user logs out:
1505
- *
1506
- * @param callback The function called when a user completes logout.
1507
- * @since 1.3.0
1508
- * @deprecated Prefer events.on(EVENTS.LOGOUT, callback)
1509
- *
1510
- */
1511
- const onLogout = (...args) => {
1512
- const session = getDefaultSession();
1513
- return session.onLogout(...args);
1514
- };
1515
- /**
1516
- * Register a callback function to be called when a session is restored:
1517
- *
1518
- * @param callback The function called when a session is restored.
1519
- * @since 1.3.0
1520
- * @deprecated Prefer events.on(EVENTS.SESSION_RESTORED, callback)
1521
- */
1522
- const onSessionRestore = (...args) => {
1523
- const session = getDefaultSession();
1524
- return session.onSessionRestore(...args);
1525
- };
1526
1422
  /**
1527
1423
  * {@link SessionEventEmitter} instance to subscribe to events by the default session.
1528
1424
  *
@@ -1533,30 +1429,26 @@ const events = () => {
1533
1429
  };
1534
1430
 
1535
1431
  Object.defineProperty(exports, 'ConfigurationError', {
1536
- enumerable: true,
1537
- get: function () { return solidClientAuthnCore.ConfigurationError; }
1432
+ enumerable: true,
1433
+ get: function () { return solidClientAuthnCore.ConfigurationError; }
1538
1434
  });
1539
1435
  Object.defineProperty(exports, 'EVENTS', {
1540
- enumerable: true,
1541
- get: function () { return solidClientAuthnCore.EVENTS; }
1436
+ enumerable: true,
1437
+ get: function () { return solidClientAuthnCore.EVENTS; }
1542
1438
  });
1543
1439
  Object.defineProperty(exports, 'InMemoryStorage', {
1544
- enumerable: true,
1545
- get: function () { return solidClientAuthnCore.InMemoryStorage; }
1440
+ enumerable: true,
1441
+ get: function () { return solidClientAuthnCore.InMemoryStorage; }
1546
1442
  });
1547
1443
  Object.defineProperty(exports, 'NotImplementedError', {
1548
- enumerable: true,
1549
- get: function () { return solidClientAuthnCore.NotImplementedError; }
1444
+ enumerable: true,
1445
+ get: function () { return solidClientAuthnCore.NotImplementedError; }
1550
1446
  });
1551
1447
  exports.Session = Session;
1552
1448
  exports.events = events;
1553
- exports.fetch = fetch;
1554
- exports.getClientAuthenticationWithDependencies = getClientAuthenticationWithDependencies;
1449
+ exports.fetch = fetch$1;
1555
1450
  exports.getDefaultSession = getDefaultSession;
1556
1451
  exports.handleIncomingRedirect = handleIncomingRedirect;
1557
1452
  exports.login = login;
1558
1453
  exports.logout = logout;
1559
- exports.onLogin = onLogin;
1560
- exports.onLogout = onLogout;
1561
- exports.onSessionRestore = onSessionRestore;
1562
1454
  //# sourceMappingURL=index.js.map